diff --git a/bash/__init__.py b/bash/__init__.py index d8da050..f51f0be 100644 --- a/bash/__init__.py +++ b/bash/__init__.py @@ -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) diff --git a/tests.py b/tests.py index 41263b4..208b366 100644 --- a/tests.py +++ b/tests.py @@ -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')