Skip to content

Commit b30cae4

Browse files
committed
document update
1 parent 53fc8e5 commit b30cae4

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

doc/specs/stdlib_system.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,44 @@ p = run("sleep 5", wait=.false.)
232232
call wait(p, max_wait_time=10.0)
233233
print *, "Process completed or timed out."
234234
```
235+
236+
## `update` - Update the internal state of a process
237+
238+
### Status
239+
240+
Experimental
241+
242+
### Description
243+
244+
The `update` interface allows the internal state of a process object to be updated by querying the system.
245+
After the process completes, the standard output and standard error are retrieved, if they were requested, and loaded into the `process%stdout` and `process%stderr` string variables, respectively.
246+
247+
This is especially useful for monitoring asynchronous processes and retrieving their output after they have finished.
248+
249+
### Syntax
250+
251+
`call ` [[stdlib_subprocess(module):update(subroutine)]] `(process)`
252+
253+
### Arguments
254+
255+
`process`: Shall be a `type(process_type)` object representing the external process whose state needs to be updated.
256+
This is an `intent(inout)` argument, and its internal state is updated on completion.
257+
258+
### Example
259+
260+
```fortran
261+
! Example usage of update
262+
type(process_type) :: p
263+
264+
! Start an asynchronous process
265+
p = run("sleep 5", wait=.false., want_stdout=.true., want_stderr=.true.)
266+
267+
! Periodically update the process state
268+
call update(p)
269+
270+
! After completion, print the captured stdout and stderr
271+
if (p%completed) then
272+
print *, "Standard Output: ", p%stdout
273+
print *, "Standard Error: ", p%stderr
274+
endif
275+
```

src/stdlib_system.F90

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,32 @@ module subroutine wait_for_completion(process, max_wait_time)
203203
end subroutine wait_for_completion
204204
end interface wait
205205

206-
207-
!> Query the system to update a process's state
208206
interface update
207+
!! version: experimental
208+
!!
209+
!! Updates the internal state of a process variable.
210+
!! ([Specification](../page/specs/stdlib_system.html#update-update-the-internal-state-of-a-process))
211+
!!
212+
!! ### Summary
213+
!! Provides a method to query the system and update the internal state of the specified process variable.
214+
!!
215+
!! ### Description
216+
!!
217+
!! This subroutine queries the system to retrieve and update information about the state of the process.
218+
!! Once the process is completed, and if standard output or standard error were requested, their respective
219+
!! data is loaded into the `process%stdout` and `process%stderr` variables. This routine is useful for keeping
220+
!! track of the latest state and output of a process, particularly for asynchronous processes.
221+
!!
222+
!! @note This subroutine should be called periodically for asynchronous processes to check their completion
223+
!! and retrieve the output.
224+
!!
209225
module subroutine update_process_state(process)
226+
!> The process object whose state needs to be updated.
210227
type(process_type), intent(inout) :: process
211228
end subroutine update_process_state
212229
end interface update
213230

231+
214232
! Kill a process
215233
interface kill
216234
module subroutine process_kill(process, success)

0 commit comments

Comments
 (0)