Permalink
Browse files

better? check for error when calling nopen(

  • Loading branch information...
1 parent 276defa commit 7326cdd774f4d7f1e94f5362f9e98b5fedb42586 @brentp committed May 11, 2012
Showing with 14 additions and 2 deletions.
  1. +3 −0 NEWS.txt
  2. +1 −1 setup.py
  3. +10 −1 src/toolshed/files.py
View
3 NEWS.txt
@@ -1,5 +1,8 @@
News
====
+0.2.0
+-----
+* better error message from Popen when using nopen("| something")
0.1.9
-----
View
2 setup.py
@@ -6,7 +6,7 @@
NEWS = open(os.path.join(here, 'NEWS.txt')).read()
-version = '0.1.9'
+version = '0.2.0'
install_requires = [
'nose',
View
11 src/toolshed/files.py
@@ -15,6 +15,8 @@
dialect = csv.excel
+class ProcessException(Exception): pass
+
def nopen(f, mode="rb"):
"""
open a file that's gzipped or return stdin for '-'
@@ -41,7 +43,14 @@ def nopen(f, mode="rb"):
return f
if f.startswith("|"):
p = Popen(f[1:], stdout=PIPE, stdin=PIPE, stderr=PIPE, shell=True)
- if mode and mode[0] == "r": return p.stdout
+ if mode and mode[0] == "r":
+ try:
+ return p.stdout
+ finally:
+ #p.wait()
+ err = p.stderr.read()
+ if len(err) or p.returncode not in (0, None):
+ raise ProcessException(err)
# if it is writable, just return the object.
return p
return {"r": sys.stdin, "w": sys.stdout}[mode[0]] if f == "-" \

0 comments on commit 7326cdd

Please sign in to comment.