handle nonzero return codes

This commit is contained in:
Harry
2014-11-04 09:27:10 +00:00
parent ff0d7a61a9
commit d4dba5602b
2 changed files with 12 additions and 2 deletions
+4 -2
View File
@@ -9,6 +9,7 @@ class Process(object):
self.environ = {}
self.cwd = None
self._stdout = None
self._returncode = None
def set_command(self, command):
@@ -39,7 +40,8 @@ class Process(object):
@property
def returncode(self):
return 0
if self._returncode is not None:
return self._returncode
def run(self):
self._subprocess = subprocess.Popen(
@@ -48,7 +50,7 @@ class Process(object):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
)
self._subprocess.wait()
self._returncode = self._subprocess.wait()
self._stdout = self._subprocess.stdout.read().decode()
+8
View File
@@ -14,3 +14,11 @@ def test_single_proc():
assert ls.returncode == 0
assert ls.stdout == u'file1\nfile2\nfile3\n'
def test_returncode():
assert not os.path.exists('/bin/nosuchcommand')
p = Process('/bin/nosuchcommand')
p.run()
assert p.returncode == 127