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.

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

Process timeout (Python >=3.3 only) On timeout and if psutil is available the children of the process are killed before the process itself

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


could not run


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