mirror of
https://github.com/kennethreitz-archive/procs.git
synced 2026-06-05 23:30:18 +00:00
handle nonzero return codes
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user