execute

execute(cmd, cwd=None, workdir=None, shell=False, is_shell=False, executable=None, shell_exe=None, hide_win=True, check=True, check_exit_code=True, get_stdout=False, get_stderr=False, timeout=None, env=None)

Launch an external process.

Parameters
cmdstr

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

cwdstr

Current directory of the executed command.

shellbool, default=False

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

executablestr, default=False

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

hide_winstr, default=True

Hide cmd.exe popup on windows platform.

checkbool, 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

envdict, default=None

Environment variables mapping for the new process

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, shell=True)
>>> ret
0
>>> int(stdout)
42