From e5460203573f54a74c06f1b0922dcbbb1076f64c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 13 Nov 2008 09:02:22 -0500 Subject: Catch OSErrors from Popen()s From the subprocess module documentation: http://www.python.org/doc/2.5.2/lib/node530.html "The most common exception raised is OSError. This occurs, for example, when trying to execute a non-existent file. Applications should prepare for OSError exceptions." And from the os module documentation: http://www.python.org/doc/2.5.2/lib/module-os.html "exception error This exception is raised when a function returns a system-related error (not for illegal argument types or other incidental errors). This is also known as the built-in exception OSError. The accompanying value is a pair containing the numeric error code from errno and the corresponding string, as would be printed by the C function perror(). See the module errno, which contains names for the error codes defined by the underlying operating system. When exceptions are classes, this exception carries two attributes, errno and strerror. The first holds the value of the C errno variable, and the latter holds the corresponding error message from strerror(). For exceptions that involve a file system path (such as chdir() or unlink()), the exception instance will contain a third attribute, filename, which is the file name passed to the function." I turned this up running be/test.py, when it defaulted to the tla client which I didn't have installed. I don't have things working yet, so I can't create a bug at the moment... --- libbe/rcs.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'libbe/rcs.py') diff --git a/libbe/rcs.py b/libbe/rcs.py index 77d6c9a..4487fba 100644 --- a/libbe/rcs.py +++ b/libbe/rcs.py @@ -59,12 +59,16 @@ class CommandError(Exception): self.status = status def invoke(args, expect=(0,), cwd=None): - if sys.platform != "win32": - q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=cwd) - else: - # win32 don't have os.execvp() so have to run command in a shell - q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True, - cwd=cwd) + try : + if sys.platform != "win32": + q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=cwd) + else: + # win32 don't have os.execvp() so have to run command in a shell + q = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True, + cwd=cwd) + except OSError, e : + strerror = "%s\nwhile executing %s" % (e.args[1], args) + raise CommandError(strerror, e.args[0]) output, error = q.communicate() status = q.wait() if status not in expect: -- cgit