system return status on Windows
Fredrik Lundh
effbot at telia.com
Fri Feb 25 03:24:06 EST 2000
Milos Prudek <prudek at nembv.cz> wrote:
> Tim Peters wrote:
> >
> > [Milos Prudek
> > You could also try os.spawnv or os.spawnve (but those only exist under
> > Windows). BTW, don't expect os.popen to work sensibly under Windows
either.
>
> Great, thanks. Could you send something about mode (magic operational
> constant) of spawnv? I do not have Visual C++ Runtime Library
> documentation...
get the eff-bot guide ;-)
# os-spawn-example-3.py
import os
import string
if os.name in ("nt", "dos"):
exefile = ".exe"
else:
exefile = ""
def spawn(program, *args):
try:
# possible 1.6 shortcut!
return os.spawnvp(program, (program,) + args)
except AttributeError:
pass
try:
spawnv = os.spawnv
except AttributeError:
# assume it's unix
pid = os.fork()
if not pid:
os.execvp(program, (program,) + args)
return os.wait()[0]
else:
# got spawnv but no spawnp: go look for an executable
for path in string.split(os.environ["PATH"], os.pathsep):
file = os.path.join(path, program) + exefile
try:
return spawnv(os.P_WAIT, file, (file,) + args)
except os.error:
pass
raise IOError, "cannot find executable"
#
# try it out!
spawn("python", "hello.py")
print "goodbye"
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list