Prev Next system_command_prc

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\W}[1]{ \; #1 \; }@)@ This is dismod_at-20221105 documentation: Here is a link to its current documentation .
Print Run and Check a System Command

Syntax
Purpose
command
print_command
return_stdout
return_stderr
file_stdout
file_stderr
write_command
result
Example

Syntax

# result = system_command_prc(
   command                ,
   print_command  = True  ,
   return_stdout  = False ,
   return_stderr  = False ,
   file_stdout    = None  ,
   file_stderr    = None  ,
   write_command  = False ,
# )

Purpose
This routine provides variations on the following steps:
  1. Print the system command as it would appear in the shell; i.e., with arguments separated by spaces.
  2. Run the system command and wait for it to complete.
  3. Check the integer value returned by the system command. If it is non-zero, an assert exception is raised with stderr as the message in the exception.
  4. Return the contents of standard out as a python string.


command
is a list with str elements. The first element is the program to execute and the other elements are arguments to the program.

print_command
If this argument is true (false) the command will (will not) be printed before it is executed.

return_stdout
If this argument is true, the command's standard output will be returned. If this argument is false and file_stdout is not None, standard error will be written to a file during the command execution. Otherwise, standard output will be printed during the command execution.

return_stderr
If this argument is true, the command's standard error will be returned. If this argument is false and file_stderr is not None, standard error will be written to a file during the command execution. Otherwise, if an error occurs, an assertion is generated with the commands standard error as the corresponding message.

file_stdout
If return_stdout is true, this argument must be None. If this argument is not None, it is a file object that is opened for writing and standard output will be written to this file.

file_stderr
If return_stderr is true, this argument must be None. If this argument is not None, it is a file object that is opened for writing and standard error will be written to this file.

write_command
If write_command is true (false) the command will (will not) be written to file_stdout . If file_stdout is None, write_command must be false.

result
  1. If return_stdout and return stderr are both false, result is None.
  2. If return_stdout is true and return_stderr is false, result is a str with the contents of standard output.
  3. If return_stderr is true and return_stdout is false, result.stderr is an str with the contents of standard error, and result.returncode is an int with the command's return code..
  4. If both return_stderr and return_stdout are true, result.stderr is an str with the contents of standard error, result.stdout is an str with the contents of standard output, and result.returncode is an int with the command's return code..


Example
Many of the user_example examples use this utility.
Input File: python/dismod_at/system_command_prc.py