Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow override of shell in local command #725

Merged
merged 2 commits into from Sep 12, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog.rst
Expand Up @@ -25,6 +25,8 @@ would have also been included in the 1.2 line.
Changelog
=========

* :feature:`725` Updated `~fabric.operations.local` to allow override
of shell. Thanks to Mustafa Khattab.
* :bug:`704` Fix up a bunch of Python 2.x style ``print`` statements to be
forwards compatible. Thanks to Francesco Del Degan for the patch.
* :feature:`491` (also :feature:`385`) IPv6 host string support. Thanks to Max
Expand Down
15 changes: 11 additions & 4 deletions fabric/operations.py
Expand Up @@ -1030,14 +1030,17 @@ def sudo(command, shell=True, pty=True, combine_stderr=None, user=None,
warn_only=warn_only, stdout=stdout, stderr=stderr)


def local(command, capture=False):
def local(command, capture=False, shell=None):
"""
Run a command on the local system.

`local` is simply a convenience wrapper around the use of the builtin
Python ``subprocess`` module with ``shell=True`` activated. If you need to
do anything special, consider using the ``subprocess`` module directly.

`shell` specifies the shell to use (e.g. /bin/bash), otherwise it
defaults in the ``subprocess`` module.

`local` is not currently capable of simultaneously printing and
capturing output, as `~fabric.operations.run`/`~fabric.operations.sudo`
do. The ``capture`` kwarg allows you to switch between printing and
Expand All @@ -1054,7 +1057,7 @@ def local(command, capture=False):
and `~fabric.operations.sudo`, this return value exhibits the
``return_code``, ``stderr``, ``failed`` and ``succeeded`` attributes. See
`run` for details.

`~fabric.operations.local` will honor the `~fabric.context_managers.lcd`
context manager, allowing you to control its current working directory
independently of the remote end (which honors
Expand Down Expand Up @@ -1087,8 +1090,12 @@ def local(command, capture=False):
err_stream = None if output.stderr else dev_null
try:
cmd_arg = wrapped_command if win32 else [wrapped_command]
p = subprocess.Popen(cmd_arg, shell=True, stdout=out_stream,
stderr=err_stream)
if shell is not None:
p = subprocess.Popen(cmd_arg, shell=True, stdout=out_stream,
stderr=err_stream, executable=shell)
else:
p = subprocess.Popen(cmd_arg, shell=True, stdout=out_stream,
stderr=err_stream)
(stdout, stderr) = p.communicate()
finally:
if dev_null is not None:
Expand Down