From 3399dd71db329039892bfd1060db13c45fb5f4b5 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Mon, 2 Jul 2018 18:35:35 -0400 Subject: [PATCH] improve error handling robustness for os.execvpe see: https://github.com/pexpect/pexpect/issues/512 --- ptyprocess/ptyprocess.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ptyprocess/ptyprocess.py b/ptyprocess/ptyprocess.py index 29b4e43..cb033c6 100644 --- a/ptyprocess/ptyprocess.py +++ b/ptyprocess/ptyprocess.py @@ -283,10 +283,14 @@ def spawn( os.execv(command, argv) else: os.execvpe(command, argv, env) - except OSError as err: + except Exception as err: # [issue #119] 5. If exec fails, the child writes the error # code back to the parent using the pipe, then exits. - tosend = 'OSError:{}:{}'.format(err.errno, str(err)) + if isinstance(err, OSError): + tosend = 'OSError:{}:{}'.format(err.errno, str(err)) + else: + cls_name = err.__class__.__name__ + tosend = 'Exception:0:{}: {}'.format(cls_name, str(err)) if PY3: tosend = tosend.encode('utf-8') os.write(exec_err_pipe_write, tosend)