portable subprocess with return value and path search

Chris Liechti cliechti at gmx.net
Tue Apr 2 17:44:19 EST 2002


joshualevy at yahoo.com (Joshua Levy) wrote in 
news:5fa44575.0204021305.600a987 at posting.google.com:

> I'm trying desperately to get python to do the following
> four things at the same time:
>     1. Run a subprocess (like "java com.foo.bar arg")
>     2. Get the process return value from that subprocess
>     3. Work on both Windows and UNIX  (I'll settle for 
>           post-Win2000 and Solaris/Linux.)
>     4. Resolve the executable, based on the current path.
>        (So I only need "java", and not "c:\jdk1.2.2\bin\java",
>        in the example above.)
> Os.system does not return values from Windows.  The versions of
> Os.spawn on Widnows do not resolve executables.
> Thanks in advance for any help.

popen seems to fulfill the above points:
>>> os.popen("exit 77").close()
77

(win2k, py2.2)

you get a file like object from popen. maybe you need to read() away the 
output so that the running app does not block because of a full stdout 
pipeline.

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list