@@ -85,31 +85,95 @@ module subroutine sleep(millisec)
8585
8686 end subroutine sleep
8787
88- ! > Open a new process
89- module function process_open_cmd (cmd ,wait ,stdin ,want_stdout ,want_stderr ) result(process)
88+ module function run_async_cmd (cmd , stdin , want_stdout , want_stderr ) result(process)
89+ ! > The command line string to execute.
90+ character (* ), intent (in ) :: cmd
91+ ! > Optional input sent to the process via standard input (stdin).
92+ character (* ), optional , intent (in ) :: stdin
93+ ! > Whether to collect standard output.
94+ logical , optional , intent (in ) :: want_stdout
95+ ! > Whether to collect standard error output.
96+ logical , optional , intent (in ) :: want_stderr
97+ ! > The output process handler.
98+ type (process_type) :: process
99+
100+ process = process_open([cmd],.false. ,stdin,want_stdout,want_stderr)
101+
102+ end function run_async_cmd
103+
104+ module function run_async_args (args , stdin , want_stdout , want_stderr ) result(process)
105+ ! > List of arguments for the process to execute.
106+ character (* ), intent (in ) :: args(:)
107+ ! > Optional input sent to the process via standard input (stdin).
108+ character (* ), optional , intent (in ) :: stdin
109+ ! > Whether to collect standard output.
110+ logical , optional , intent (in ) :: want_stdout
111+ ! > Whether to collect standard error output.
112+ logical , optional , intent (in ) :: want_stderr
113+ ! > The output process handler.
114+ type (process_type) :: process
115+
116+ process = process_open(args,.false. ,stdin,want_stdout,want_stderr)
117+
118+ end function run_async_args
119+
120+ module function run_sync_cmd (cmd , stdin , want_stdout , want_stderr ) result(process)
121+ ! > The command line string to execute.
122+ character (* ), intent (in ) :: cmd
123+ ! > Optional input sent to the process via standard input (stdin).
124+ character (* ), optional , intent (in ) :: stdin
125+ ! > Whether to collect standard output.
126+ logical , optional , intent (in ) :: want_stdout
127+ ! > Whether to collect standard error output.
128+ logical , optional , intent (in ) :: want_stderr
129+ ! > The output process handler.
130+ type (process_type) :: process
131+
132+ process = process_open([cmd],.true. ,stdin,want_stdout,want_stderr)
133+
134+ end function run_sync_cmd
135+
136+ module function run_sync_args (args , stdin , want_stdout , want_stderr ) result(process)
137+ ! > List of arguments for the process to execute.
138+ character (* ), intent (in ) :: args(:)
139+ ! > Optional input sent to the process via standard input (stdin).
140+ character (* ), optional , intent (in ) :: stdin
141+ ! > Whether to collect standard output.
142+ logical , optional , intent (in ) :: want_stdout
143+ ! > Whether to collect standard error output.
144+ logical , optional , intent (in ) :: want_stderr
145+ ! > The output process handler.
146+ type (process_type) :: process
147+
148+ process = process_open(args,.true. ,stdin,want_stdout,want_stderr)
149+
150+ end function run_sync_args
151+
152+ ! > Internal function: open a new process from a command line
153+ function process_open_cmd (cmd ,wait ,stdin ,want_stdout ,want_stderr ) result(process)
90154 ! > The command and arguments
91155 character (* ), intent (in ) :: cmd
92156 ! > Optional character input to be sent to the process via pipe
93157 character (* ), optional , intent (in ) :: stdin
94158 ! > Define if the process should be synchronous (wait=.true.), or asynchronous(wait=.false.)
95- logical , optional , intent (in ) :: wait
159+ logical , intent (in ) :: wait
96160 ! > Require collecting output
97161 logical , optional , intent (in ) :: want_stdout, want_stderr
98162 ! > The output process handler
99163 type (process_type) :: process
100164
101- process = process_open_args ([cmd],wait,stdin,want_stdout,want_stderr)
165+ process = process_open ([cmd],wait,stdin,want_stdout,want_stderr)
102166
103167 end function process_open_cmd
104168
105- ! > Open a new process
106- module function process_open_args (args ,wait ,stdin ,want_stdout ,want_stderr ) result(process)
169+ ! > Internal function: open a new process from arguments
170+ function process_open (args ,wait ,stdin ,want_stdout ,want_stderr ) result(process)
107171 ! > The command and arguments
108172 character (* ), intent (in ) :: args(:)
109173 ! > Optional character input to be sent to the process via pipe
110174 character (* ), optional , intent (in ) :: stdin
111175 ! > Define if the process should be synchronous (wait=.true.), or asynchronous(wait=.false.)
112- logical , optional , intent (in ) :: wait
176+ logical , intent (in ) :: wait
113177 ! > Require collecting output
114178 logical , optional , intent (in ) :: want_stdout, want_stderr
115179 ! > The output process handler
@@ -121,11 +185,10 @@ module function process_open_args(args,wait,stdin,want_stdout,want_stderr) resul
121185 integer (TICKS) :: count_max
122186
123187 ! Process user requests
124- asynchronous = .false.
188+ asynchronous = .not. wait
125189 collect_stdout = .false.
126190 collect_stderr = .false.
127191 has_stdin = present (stdin)
128- if (present (wait)) asynchronous = .not. wait
129192 if (present (want_stdout)) collect_stdout = want_stdout
130193 if (present (want_stderr)) collect_stderr = want_stderr
131194
@@ -173,7 +236,7 @@ module function process_open_args(args,wait,stdin,want_stdout,want_stderr) resul
173236 ! Run a first update
174237 call update_process_state(process)
175238
176- end function process_open_args
239+ end function process_open
177240
178241 subroutine launch_asynchronous (process , args , stdin )
179242 class(process_type), intent (inout ) :: process
0 commit comments