Skip to content

Latest commit

 

History

History
28 lines (17 loc) · 642 Bytes

with.rst

File metadata and controls

28 lines (17 loc) · 642 Bytes

'With' Contexts

Commands can be run within a Python with context. Popular commands using this might be sudo or fakeroot:

with sh.contrib.sudo:
    print(ls("/root"))
.. seealso::

    :ref:`contrib_sudo`

If you need to run a command in a with context and pass in arguments, for example, specifying a -p prompt with sudo, you need to use the :ref:`_with=True <with>` This let's the command know that it's being run from a with context so it can behave correctly:

with sh.contrib.sudo(k=True, _with=True):
    print(ls("/root"))