From 34e88f681cf090b778787c6412bcd035ea48aa6e Mon Sep 17 00:00:00 2001 From: Niklas Heer Date: Fri, 8 Dec 2017 17:32:52 +0100 Subject: [PATCH 1/2] Add cwd argument --- bash/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) From 7aabf75888caa984edc313519232053397b90df8 Mon Sep 17 00:00:00 2001 From: Niklas Heer Date: Fri, 8 Dec 2017 17:33:06 +0100 Subject: [PATCH 2/2] Add tests for cwd behaviour --- tests.py | 6 ++++++ 1 file changed, 6 insertions(+) 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')