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

Function run_command

st2common/st2common/util/shell.py:42–110  ·  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,
    close_fds=None,
)

Source from the content-addressed store, hash-verified

40
41# pylint: disable=too-many-function-args
42def run_command(
43 cmd,
44 stdin=None,
45 stdout=subprocess.PIPE,
46 stderr=subprocess.PIPE,
47 shell=False,
48 cwd=None,
49 env=None,
50 close_fds=None,
51):
52 """
53 Run the provided command in a subprocess and wait until it completes.
54
55 :param cmd: Command to run.
56 :type cmd: ``str`` or ``list``
57
58 :param stdin: Process stdin.
59 :type stdin: ``object``
60
61 :param stdout: Process stdout.
62 :type stdout: ``object``
63
64 :param stderr: Process stderr.
65 :type stderr: ``object``
66
67 :param shell: True to use a shell.
68 :type shell ``boolean``
69
70 :param cwd: Optional working directory.
71 :type cwd: ``str``
72
73 :param env: Optional environment to use with the command. If not provided,
74 environment from the current process is inherited.
75 :type env: ``dict``
76
77 :param close_fds: True to close all the fds. By default when None is provided we rely on
78 default upstream behavior which may be Python version specific.
79
80 :rtype: ``tuple`` (exit_code, stdout, stderr)
81 """
82 if not isinstance(cmd, (list, tuple) + six.string_types):
83 raise TypeError(
84 f"Command must be a type of list, tuple, or string, not '{type(cmd)}'."
85 )
86
87 if not env:
88 env = os.environ.copy()
89
90 kwargs = {}
91 if close_fds is not None:
92 kwargs["close_fds"] = close_fds
93
94 process = concurrency.subprocess_popen(
95 args=cmd,
96 stdin=stdin,
97 stdout=stdout,
98 stderr=stderr,
99 env=env,

Calls

no outgoing calls