Grokbase Groups Python tutor May 2005
FAQ

http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/68786
As a work around, I end up calling popen3 like this:

Open3.popen3 ("/some/command/to/run ; echo $? 1>&2") { ... }

That ensures the exit code from /some/command/to/run will be the last
line of the standard error stream from Open3.popen3. Then I can just
pull that line off the output to get the return code.

Hi Jeffrey,

Ah! Ok, you're looking for the error code too.


Is there a more elegant way to get the exitcode off the child process,
or is this the "approved" method?
Yeah; check the Popen3 object in the 'popen2' module: it has a separate
way of getting at the error code:

http://www.python.org/doc/lib/popen3-objects.html


For example:

######
import popen2
process = popen2.Popen3(['wc'])
process.tochild.write("hello\nworld")
process.tochild.close()
process.fromchild.read()
' 1 2 11\n'
process.fromchild.close()
process.wait()
######


Hope this helps!

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 5 | next ›
Discussion Overview
grouptutor @
categoriespython
postedMay 12, '05 at 5:56p
activeMay 12, '05 at 11:10p
posts5
users2
websitepython.org

2 users in discussion

Danny Yoo: 3 posts Jeffrey Rice: 2 posts

People

Translate

site design / logo © 2022 Grokbase