diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/os.py | 8 | ||||
-rw-r--r-- | Lib/test/test_popen.py | 7 |
2 files changed, 14 insertions, 1 deletions
@@ -643,7 +643,13 @@ class _wrap_close: self._proc = proc def close(self): self._stream.close() - return self._proc.wait() << 8 # Shift left to match old behavior + returncode = self._proc.wait() + if returncode == 0: + return None + if name == 'nt': + return returncode + else: + return returncode << 8 # Shift left to match old behavior def __getattr__(self, name): return getattr(self._stream, name) def __iter__(self): diff --git a/Lib/test/test_popen.py b/Lib/test/test_popen.py index d728792..99ad41d 100644 --- a/Lib/test/test_popen.py +++ b/Lib/test/test_popen.py @@ -42,6 +42,13 @@ class PopenTest(unittest.TestCase): ) support.reap_children() + def test_return_code(self): + self.assertEqual(os.popen("exit 0").close(), None) + if os.name == 'nt': + self.assertEqual(os.popen("exit 42").close(), 42) + else: + self.assertEqual(os.popen("exit 42").close(), 42 << 8) + def test_main(): support.run_unittest(PopenTest) |