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 processus in a clean way.


cmd : str, representing the command.

e.g.: “ls -l /home”

workdir : str, current directory of the executed command

is_shell : bool, if set to True, the command is started in a shell (bash).

default: False.

shell_exe : str, path to the shell. e.g. /bin/zsh.

default: None -> /bin/bash.

hide_win : str, hide cmd.exe popup on windows

check_exit_code : bool, if set to True: raise a RuntimeError exception if return

code of process != 0

get_stdout : bool, whether standard output of the command is returned

get_stderr : bool, whether standard error of the command is returned

timeout : int, child process timeout (Python >= 3.3 only)


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


>>> # ret, stdout = execute('/bin/ls /bin/kill', get_stdout=True).
>>> ## => ret = 0, stdout = '/bin/kill'