MCPcopy Create free account
hub / github.com/StackStorm/st2 / run_command

Function run_command

st2common/st2common/util/green/shell.py:37–240  ·  view source on GitHub ↗

Run the provided command in a subprocess and wait until it completes. :param cmd: Command to run. :type cmd: ``str`` or ``list`` :param stdin: Process stdin. :type stdin: ``object`` :param stdout: Process stdout. :type stdout: ``object`` :param stderr: Process st

(
    cmd,
    stdin=None,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    shell=False,
    cwd=None,
    env=None,
    timeout=60,
    preexec_func=None,
    kill_func=None,
    read_stdout_func=None,
    read_stderr_func=None,
    read_stdout_buffer=None,
    read_stderr_buffer=None,
    stdin_value=None,
    bufsize=0,
)

Source from the content-addressed store, hash-verified

35
36
37def run_command(
38 cmd,
39 stdin=None,
40 stdout=subprocess.PIPE,
41 stderr=subprocess.PIPE,
42 shell=False,
43 cwd=None,
44 env=None,
45 timeout=60,
46 preexec_func=None,
47 kill_func=None,
48 read_stdout_func=None,
49 read_stderr_func=None,
50 read_stdout_buffer=None,
51 read_stderr_buffer=None,
52 stdin_value=None,
53 bufsize=0,
54):
55 """
56 Run the provided command in a subprocess and wait until it completes.
57
58 :param cmd: Command to run.
59 :type cmd: ``str`` or ``list``
60
61 :param stdin: Process stdin.
62 :type stdin: ``object``
63
64 :param stdout: Process stdout.
65 :type stdout: ``object``
66
67 :param stderr: Process stderr.
68 :type stderr: ``object``
69
70 :param shell: True to use a shell.
71 :type shell ``boolean``
72
73 :param cwd: Optional working directory.
74 :type cwd: ``str``
75
76 :param env: Optional environment to use with the command. If not provided,
77 environment from the current process is inherited.
78 :type env: ``dict``
79
80 :param timeout: How long to wait before timing out.
81 :type timeout: ``float``
82
83 :param preexec_func: Optional pre-exec function.
84 :type preexec_func: ``callable``
85
86 :param kill_func: Optional function which will be called on timeout to kill the process.
87 If not provided, it defaults to `process.kill`
88
89 NOTE: If you are utilizing shell=True, you shoulf always specify a custom
90 kill function which correctly kills shell process + the shell children
91 process.
92
93 If you don't do that, timeout handler won't work correctly / as expected -
94 only the shell process will be killed, but not also the child processs

Callers

nothing calls this directly

Calls 3

writeMethod · 0.80
waitMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected