Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def __init__(self, *args, **kwargs):
self.stdout = None
self.bash(*args, **kwargs)

def bash(self, cmd, env=None, stdout=PIPE, stderr=PIPE, timeout=None, sync=True):
def bash(self, cmd, env=None, stdout=PIPE, stderr=PIPE, timeout=None, sync=True, cwd=None):
self.p = Popen(
cmd, shell=True, stdout=stdout, stdin=PIPE, stderr=stderr, env=env
cmd, shell=True, stdout=stdout, stdin=PIPE, stderr=stderr, env=env, cwd=cwd
)
if sync:
self.sync(timeout)
Expand Down
6 changes: 6 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ def test_sync_false_does_not_wait(self):
self.assertTrue((t2-t1).total_seconds() < 0.5)
b.sync()
self.assertEqual(b.stdout, b'1\n')

def test_cwd_works(self):
without_cwd = bash('echo $PWD')
with_cwd = bash('echo $PWD', cwd='/tmp')
self.assertNotEqual(without_cwd, with_cwd)
self.assertEqual(str(with_cwd), '/tmp')