execute

execute(cmd, workdir=None, is_shell=False, shell_exe=None, hide_win=True, check_exit_code=True, get_stdout=False, get_stderr=False, timeout=None)

Launch an external process.

Parameters:

cmd : str

Command line to execute, e.g.: “echo 42”

workdir : str

Current directory of the executed command.

is_shell : bool, default=False

If set to True, the command is started in a shell (bash).

shell_exe : str, default=False

path to the shell. e.g. /bin/zsh.

hide_win : str, default=True

Hide cmd.exe popup on windows platform.

check_exit_code : bool, default=True

If set to True: raise a RuntimeError exception if return code of process != 0

get_stdout : bool, default=False

Whether the standard output of the command is returned

get_stderr : bool, default=False

Whether the standard error of the command is returned

timeout : int

Child process timeout (Python >= 3.3 only)

Returns:

ret : int

The exit code of the command

stdout_data : str

The stdout data if get_stdout parameter is set

stderr_data : str

The stderr data if get_stderr parameter is set

Raises:

RuntimeError

could not run

Examples

>>> import openturns.coupling_tools as otct
>>> ret, stdout = otct.execute('echo 42', get_stdout=True, is_shell=True)
>>> ret
0
>>> int(stdout)
42