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
cmdstr

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

workdirstr

Current directory of the executed command.

is_shellbool, default=False

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

shell_exestr, default=False

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

hide_winstr, default=True

Hide cmd.exe popup on windows platform.

check_exit_codebool, default=True

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

get_stdoutbool, default=False

Whether the standard output of the command is returned

get_stderrbool, default=False

Whether the standard error of the command is returned

timeoutint

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

Returns
retint

The exit code of the command

stdout_datastr

The stdout data if get_stdout parameter is set

stderr_datastr

The stderr data if get_stderr parameter is set

Raises
RuntimeError

could not run

Examples

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