MCPcopy Create free account
hub / github.com/saltstack/salt / run

Function run

salt/modules/cmdmod.py:1164–1504  ·  view source on GitHub ↗

r""" Execute the passed command and return the output as a string :param str cmd: The command to run. ex: ``ls -lart /home`` :param str cwd: The directory from which to execute the command. Defaults to the home directory of the user specified by ``runas`` (or the user u

(
    cmd,
    cwd=None,
    stdin=None,
    runas=None,
    group=None,
    shell=DEFAULT_SHELL,
    python_shell=None,
    env=None,
    clean_env=False,
    template=None,
    rstrip=True,
    umask=None,
    output_encoding=None,
    output_loglevel="debug",
    log_callback=None,
    hide_output=False,
    timeout=None,
    reset_system_locale=True,
    ignore_retcode=False,
    saltenv=None,
    use_vt=False,
    redirect_stderr=True,
    bg=False,
    password=None,
    encoded_cmd=False,
    raise_err=False,
    prepend_path=None,
    success_retcodes=None,
    success_stdout=None,
    success_stderr=None,
    **kwargs,
)

Source from the content-addressed store, hash-verified

1162
1163
1164def run(
1165 cmd,
1166 cwd=None,
1167 stdin=None,
1168 runas=None,
1169 group=None,
1170 shell=DEFAULT_SHELL,
1171 python_shell=None,
1172 env=None,
1173 clean_env=False,
1174 template=None,
1175 rstrip=True,
1176 umask=None,
1177 output_encoding=None,
1178 output_loglevel="debug",
1179 log_callback=None,
1180 hide_output=False,
1181 timeout=None,
1182 reset_system_locale=True,
1183 ignore_retcode=False,
1184 saltenv=None,
1185 use_vt=False,
1186 redirect_stderr=True,
1187 bg=False,
1188 password=None,
1189 encoded_cmd=False,
1190 raise_err=False,
1191 prepend_path=None,
1192 success_retcodes=None,
1193 success_stdout=None,
1194 success_stderr=None,
1195 **kwargs,
1196):
1197 r"""
1198 Execute the passed command and return the output as a string
1199
1200 :param str cmd: The command to run. ex: ``ls -lart /home``
1201
1202 :param str cwd: The directory from which to execute the command. Defaults
1203 to the home directory of the user specified by ``runas`` (or the user
1204 under which Salt is running if ``runas`` is not specified).
1205
1206 :param str stdin: A string of standard input can be specified for the
1207 command to be run using the ``stdin`` parameter. This can be useful in
1208 cases where sensitive information must be read from standard input.
1209
1210 :param str runas: Specify an alternate user to run the command. The default
1211 behavior is to run as the user under which Salt is running.
1212
1213 .. warning::
1214
1215 For versions 2018.3.3 and above on MacOS while using runas,
1216 on linux while using run, to pass special characters to the
1217 command you need to escape the characters on the shell.
1218
1219 Example:
1220
1221 .. code-block:: bash

Callers 1

shellFunction · 0.70

Calls 9

_python_shell_defaultFunction · 0.85
_check_cbFunction · 0.85
_check_loglevelFunction · 0.85
_log_cmdFunction · 0.85
formatMethod · 0.80
_runFunction · 0.70
getMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected