Skip to content

Commit 4d5eb32

Browse files
committed
run/runasync docs
1 parent a1aaf2f commit 4d5eb32

File tree

2 files changed

+60
-23
lines changed

2 files changed

+60
-23
lines changed

doc/specs/stdlib_system.md

+46-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and monitoring of system commands or applications directly from Fortran.
99

1010
[TOC]
1111

12-
## `run` - Execute an external process
12+
## `run` - Execute an external process synchronously
1313

1414
### Status
1515

@@ -18,18 +18,57 @@ Experimental
1818
### Description
1919

2020
The `run` interface allows execution of external processes using a single command string or a list of arguments.
21-
Processes can be run either synchronously (blocking execution until the process finishes) or asynchronously (non-blocking execution).
21+
Processes run synchronously, meaning execution is blocked until the process finishes.
2222
Optional arguments enable the collection of standard output and error streams, as well as sending input via standard input.
2323

2424
### Syntax
2525

26-
`process = ` [[stdlib_subprocess(module):run(interface)]] `(args [, wait] [, stdin] [, want_stdout] [, want_stderr])`
26+
`process = ` [[stdlib_subprocess(module):run(interface)]] `(args [, stdin] [, want_stdout] [, want_stderr])`
2727

2828
### Arguments
2929

3030
`args`: Shall be a `character(*)` string (for command-line execution) or a `character(*), dimension(:)` array (for argument-based execution). It specifies the command and arguments to execute. This is an `intent(in)` argument.
3131

32-
`wait` (optional): Shall be a `logical` flag. If `.true.` (default), the process will execute synchronously (blocking). If `.false.`, the process will execute asynchronously (non-blocking). This is an `intent(in)` argument.
32+
`stdin` (optional): Shall be a `character(*)` value containing input to send to the process via standard input (pipe). This is an `intent(in)` argument.
33+
34+
`want_stdout` (optional): Shall be a `logical` flag. If `.true.`, the standard output of the process will be captured; if `.false.` (default), it will be lost. This is an `intent(in)` argument.
35+
36+
`want_stderr` (optional): Shall be a logical flag. If `.true.`, the standard error output of the process will be captured. Default: `.false.`. This is an `intent(in)` argument.
37+
38+
### Return Value
39+
40+
Returns an object of type `process_type` that contains information about the state of the created process.
41+
42+
### Example
43+
44+
```fortran
45+
! Example usage with command line or list of arguments
46+
type(process_type) :: p
47+
48+
! Run a simple command line synchronously
49+
p = run("echo 'Hello, world!'", want_stdout=.true.)
50+
```
51+
52+
53+
## `runasync` - Execute an external process asynchronously
54+
55+
### Status
56+
57+
Experimental
58+
59+
### Description
60+
61+
The `runasync` interface allows execution of external processes using a single command string or a list of arguments.
62+
Processes are run asynchronously (non-blocking), meaning execution does not wait for the process to finish.
63+
Optional arguments enable the collection of standard output and error streams, as well as sending input via standard input.
64+
65+
### Syntax
66+
67+
`process = ` [[stdlib_subprocess(module):runasync(interface)]] `(args [, stdin] [, want_stdout] [, want_stderr])`
68+
69+
### Arguments
70+
71+
`args`: Shall be a `character(*)` string (for command-line execution) or a `character(*), dimension(:)` array (for argument-based execution). It specifies the command and arguments to execute. This is an `intent(in)` argument.
3372

3473
`stdin` (optional): Shall be a `character(*)` value containing input to send to the process via standard input (pipe). This is an `intent(in)` argument.
3574

@@ -47,11 +86,11 @@ Returns an object of type `process_type` that contains information about the sta
4786
! Example usage with command line or list of arguments
4887
type(process_type) :: p(2)
4988
50-
! Run a simple command line synchronously
51-
p(1) = run("echo 'Hello, world!'", wait=.true., want_stdout=.true.)
89+
! Run a simple command line asynchronously
90+
p(1) = runasync("echo 'Hello, world!'", want_stdout=.true.)
5291
5392
! Run a command using an argument list asynchronously
54-
p(2) = run(["/usr/bin/ls", "-l"], wait=.false.)
93+
p(2) = runasync(["/usr/bin/ls", "-l"], want_stdout=.true.)
5594
```
5695

5796
## `is_running` - Check if a process is still running

src/stdlib_system.F90

+14-16
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,18 @@ module stdlib_system
5757
interface runasync
5858
!! version: experimental
5959
!!
60-
!! Executes an external process, either synchronously or asynchronously.
61-
!! ([Specification](../page/specs/stdlib_system.html#run-execute-an-external-process))
60+
!! Executes an external process asynchronously.
61+
!! ([Specification](../page/specs/stdlib_system.html#run-execute-an-external-process-asynchronously))
6262
!!
6363
!! ### Summary
64-
!! Provides methods for executing external processes via a single command string or an argument list,
65-
!! with options for synchronous or asynchronous execution and output collection.
64+
!! Provides methods for executing external processes asynchronously, using either a single command string
65+
!! or an argument list, with options for output collection and standard input.
6666
!!
6767
!! ### Description
6868
!!
69-
!! This interface allows the user to spawn external processes using either a single command string
70-
!! or a list of arguments. Processes can be executed synchronously (blocking) or asynchronously
71-
!! (non-blocking), with optional request to collect standard output and error streams, or to provide
72-
!! a standard input stream via a `character` string.
69+
!! This interface allows the user to spawn external processes asynchronously (non-blocking).
70+
!! Processes can be executed via a single command string or a list of arguments, with options to collect
71+
!! standard output and error streams, or to provide a standard input stream via a `character` string.
7372
!!
7473
!! @note The implementation depends on system-level process management capabilities.
7574
!!
@@ -103,19 +102,18 @@ end function run_async_args
103102
interface run
104103
!! version: experimental
105104
!!
106-
!! Executes an external process, either synchronously or asynchronously.
107-
!! ([Specification](../page/specs/stdlib_system.html#run-execute-an-external-process))
105+
!! Executes an external process synchronously.
106+
!! ([Specification](../page/specs/stdlib_system.html#runasync-execute-an-external-process-synchronously))
108107
!!
109108
!! ### Summary
110-
!! Provides methods for executing external processes via a single command string or an argument list,
111-
!! with options for synchronous or asynchronous execution and output collection.
109+
!! Provides methods for executing external processes synchronously, using either a single command string
110+
!! or an argument list, with options for output collection and standard input.
112111
!!
113112
!! ### Description
114113
!!
115-
!! This interface allows the user to spawn external processes using either a single command string
116-
!! or a list of arguments. Processes can be executed synchronously (blocking) or asynchronously
117-
!! (non-blocking), with optional request to collect standard output and error streams, or to provide
118-
!! a standard input stream via a `character` string.
114+
!! This interface allows the user to spawn external processes synchronously (blocking),
115+
!! via either a single command string or a list of arguments. It also includes options to collect
116+
!! standard output and error streams, or to provide a standard input stream via a `character` string.
119117
!!
120118
!! @note The implementation depends on system-level process management capabilities.
121119
!!

0 commit comments

Comments
 (0)