Generate and return failed = .false.
if the attempt to run the requested shell command is successful.
Otherwise, return failed = .true.
indicating the occurrence of an error.
This procedure provides a convenient functional interface to the Fortran intrinsic execute_command_line()
by automatically interpreting the output error codes and reporting the failure as the function output if it occurs.
- Parameters
-
[in] | command | : The input scalar character of default kind SK containing the system shell command to run. |
[in] | wait | : The input scalar logical of default kind LK with the same functionality as the wait argument of the Fortran intrinsic execute_command_line() .
-
If
.true. , the procedure will wait for the command to terminate before returning the control to the Fortran program.
-
Otherwise, the process of running the requested shell command will be done asynchronously.
(optional, default = .true. ) |
[in,out] | exitstat | : The input/output scalar integer of default kind IK with the same functionality as the exitstat argument of the Fortran intrinsic execute_command_line() .
On output, it is assigned the process exit status from the command, only if wait = .true. . If wait = .false. , the value of exitstat remains untouched.
The value and meaning of this output argument is system dependent, but a non-zero value typically indicates the occurrence of an error within the execution of the specified command .
(optional. If missing, no exit status will be returned.) |
[out] | cmdstat | : The output scalar integer of default kind IK with the same functionality as the cmdstat argument of the Fortran intrinsic execute_command_line() .
On output, it is assigned
-
0 if the process of running the requested shell command terminates without error,
-
-1 if the processor does not support command execution,
-
-2 if wait = .true. is specified but the processor does not support asynchronous command execution,
-
a positive value if any other error occurs.
(optional. If missing, no cmdstat will be returned.) |
[in,out] | cmdmsg | : The input/output scalar character of default kind SK of arbitrary length type parameter the same functionality as the cmdmsg argument of the Fortran intrinsic execute_command_line() .
If present and the output cmdstat is assigned a positive value, then cmdmsg will be assigned an explanatory message describing the nature of the error that has occurred.
If the length of cmdstat is too short for the output error message, the message tail will be clipped as needed.
A length of LEN_IOMSG characters for cmdmsg is likely enough to capture most error messages in full.
(optional. If missing, no error message will be output.) |
- Returns
failed
: The output scalar logical
of default kind LK. It is .true.
if and only if an error occurs while running the command
.
The failure is determined by checking for a non-zero value of cmdstat
.
The specific value of exitstat
depends on both the processor and the specified value for the input argument wait
.
Moreover, the processor may execute the specified command
without failure even though exitstat
indicates the occurrence of an error within the command.
As such, the output value of exitstat
has no impact on the value of the output failed
.
Possible calling interfaces ⛓
logical(LK) :: failed
failed
= isFailedExec(command,
wait = wait, exitstat
= exitstat, cmdstat
= cmdstat, cmdmsg
= cmdmsg)
Generate and return failed = .false. if the attempt to run the requested shell command is successful....
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
This module contains procedures and generic interfaces for inferring the runtime system shell type an...
- Warning
- This procedure is prone to abuse by requesting to run system commands with devastating consequences.
- See also
- shell_type
Example usage ⛓
10 character(:, SK),
allocatable :: file
11 character(
255, SK) :: cmdmsg
= SK_
""
12 integer(IK) :: cmdstat
13 integer(IK) :: exitstat
= -huge(
0_IK)
14 logical(LK) :: cmdExecFailed
16 type(display_type) :: disp
20 call disp%show(
"cmdExecFailed = isFailedExec(SK_'')")
27 call disp%show(
"cmdExecFailed = isFailedExec(SK_'ls')")
34 call disp%show(
"file = getPathNew() ! Create a file name unique in the current directory.")
37 call disp%show( file , deliml
= SK_
"""" )
40 call disp%show(
"cmdExecFailed = isFailedExec(SK_'echo 2>'//file) ! Create an empty file in the current directory.")
49 call disp%show(
"cmdExecFailed = isFailedExec(SK_'ls', wait = .false._LK) ! run the Bash command asynchronously.")
56 call disp%show(
"cmdExecFailed = isFailedExec(SK_'', exitstat = exitstat, cmdstat = cmdstat, cmdmsg = cmdmsg)")
57 cmdExecFailed
= isFailedExec(SK_
'', exitstat
= exitstat, cmdstat
= cmdstat, cmdmsg
= cmdmsg)
65 call disp%show(
trim(cmdmsg) , deliml
= SK_
"""" )
69 call disp%show(
"cmdExecFailed = isFailedExec(SK_'dir', exitstat = exitstat, cmdstat = cmdstat, cmdmsg = cmdmsg)")
70 cmdExecFailed
= isFailedExec(SK_
'dir', exitstat
= exitstat, cmdstat
= cmdstat, cmdmsg
= cmdmsg)
78 call disp%show(
trim(cmdmsg) , deliml
= SK_
"""" )
This is a generic method of the derived type display_type with pass attribute.
This is a generic method of the derived type display_type with pass attribute.
Generate and return a unique (directory or file) path name in the specified directory or the default ...
Generate and return .true. is the input path is a file (not a directory), otherwise return ....
This module contains classes and procedures for input/output (IO) or generic display operations on st...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
This module contains classes and procedures for manipulating system file/folder paths.
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
14"new_20241114_224808_081_pid_1"
29cmdExecFailed
= isFailedExec(SK_
'', exitstat
= exitstat, cmdstat
= cmdstat, cmdmsg
= cmdmsg)
40cmdExecFailed
= isFailedExec(SK_
'dir', exitstat
= exitstat, cmdstat
= cmdstat, cmdmsg
= cmdmsg)
- Test:
- test_pm_sysShell
- Todo:
- Low Priority: The current Fortran standard 202x does not allow passing characters of non-default kind to Fortran intrinsic procedures.
This generic interface should be extended to in the future to support non-default character kinds when they fully supported by the Fortran intrinsic procedures.
Final Remarks ⛓
If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.
-
If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
-
If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.
This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.
- Copyright
- Computational Data Science Lab
- Author:
- Amir Shahmoradi, Tuesday March 7, 2017, 3:09 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin
Definition at line 1141 of file pm_sysShell.F90.