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

Function shell

salt/modules/cmdmod.py:1507–1775  ·  view source on GitHub ↗

Execute the passed command and return the output as a string. .. versionadded:: 2015.5.0 :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 ``r

(
    cmd,
    cwd=None,
    stdin=None,
    runas=None,
    group=None,
    shell=DEFAULT_SHELL,
    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,
    bg=False,
    password=None,
    prepend_path=None,
    success_retcodes=None,
    success_stdout=None,
    success_stderr=None,
    **kwargs,
)

Source from the content-addressed store, hash-verified

1505
1506
1507def shell(
1508 cmd,
1509 cwd=None,
1510 stdin=None,
1511 runas=None,
1512 group=None,
1513 shell=DEFAULT_SHELL,
1514 env=None,
1515 clean_env=False,
1516 template=None,
1517 rstrip=True,
1518 umask=None,
1519 output_encoding=None,
1520 output_loglevel="debug",
1521 log_callback=None,
1522 hide_output=False,
1523 timeout=None,
1524 reset_system_locale=True,
1525 ignore_retcode=False,
1526 saltenv=None,
1527 use_vt=False,
1528 bg=False,
1529 password=None,
1530 prepend_path=None,
1531 success_retcodes=None,
1532 success_stdout=None,
1533 success_stderr=None,
1534 **kwargs,
1535):
1536 """
1537 Execute the passed command and return the output as a string.
1538
1539 .. versionadded:: 2015.5.0
1540
1541 :param str cmd: The command to run. ex: ``ls -lart /home``
1542
1543 :param str cwd: The directory from which to execute the command. Defaults
1544 to the home directory of the user specified by ``runas`` (or the user
1545 under which Salt is running if ``runas`` is not specified).
1546
1547 :param str stdin: A string of standard input can be specified for the
1548 command to be run using the ``stdin`` parameter. This can be useful in
1549 cases where sensitive information must be read from standard input.
1550
1551 :param str runas: Specify an alternate user to run the command. The default
1552 behavior is to run as the user under which Salt is running.
1553
1554 .. warning::
1555
1556 For versions 2018.3.3 and above on MacOS while using runas,
1557 to pass special characters to the command you need to escape
1558 the characters on the shell.
1559
1560 Example:
1561
1562 .. code-block:: bash
1563
1564 cmd.shell 'echo '\\''h=\\"baz\\"'\\''' runas=macuser

Callers

nothing calls this directly

Calls 2

runFunction · 0.70
popMethod · 0.45

Tested by

no test coverage detected