File: example_process_1.f90

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (24 lines) | stat: -rw-r--r-- 736 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
! Process example 1: Run a Command Synchronously and Capture Output
program run_sync
    use stdlib_system, only: run, is_completed, is_windows, process_type
    implicit none

    type(process_type) :: p
    logical :: completed

    ! Run a synchronous process to list directory contents
    if (is_windows()) then
        p = run("dir", want_stdout=.true.)
    else
        p = run("ls -l", want_stdout=.true.)
    end if

    ! Check if the process is completed (should be true since wait=.true.)
    if (is_completed(p)) then
        print *, "Process completed successfully. The current directory: "
        print *, p%stdout
    else
        print *, "Process is still running (unexpected)."
    end if
    
end program run_sync