Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use withs
Browse files Browse the repository at this point in the history
JohnLZeller committed Sep 3, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 935d7f1 commit a743675
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions utils/subprocess_output.py
Original file line number Diff line number Diff line change
@@ -18,19 +18,19 @@ def get_subprocess_output(command, log, shell=None, stdin=None):
# docs warn that the data read is buffered in memory. They suggest not to
# use subprocess.PIPE if the data size is large or unlimited.
with tempfile.TemporaryFile('rw') as stdout_f:
stderr_f = tempfile.TemporaryFile('rw')
proc = subprocess.Popen(command, close_fds=True, shell=shell, stdin=stdin,
stdout=stdout_f, stderr=stderr_f)
proc.wait()
stderr_f.seek(0)
err = stderr_f.read()
stderr_f.close()
if err:
log.debug("Error while running {0} : {1}".format(" ".join(command),
err))

stdout_f.seek(0)
output = stdout_f.read()
with tempfile.TemporaryFile('rw') as stderr_f:
proc = subprocess.Popen(command, close_fds=True, shell=shell,
stdin=stdin, stdout=stdout_f,
stderr=stderr_f)
proc.wait()
stderr_f.seek(0)
err = stderr_f.read()
if err:
log.debug("Error while running {0} : {1}".format(" ".join(command),
err))

stdout_f.seek(0)
output = stdout_f.read()
return output


0 comments on commit a743675

Please sign in to comment.