[Tutor] Using os.spawn commands
Sheila King
sheila@thinkspot.net
Sat, 09 Feb 2002 12:06:02 -0800
I wanted to write a script to test this other script of mine.
I thought one of the os.spawn commands would be best, so that if one of
the test processes crashed, at least my testing script wouldn't? (That
is correct thinking there, right?)
I'm running a lot of my testing on a Windows machine, and according to
the docs, that eliminates any of the spawn commands with a "p" as a
choice. OK, fine. That leaves me with these choices:
spawnl
spawnle
spawnv
spawnve
And the docs say, that if you know the number of parameters, might as
well use one of the "l" versions, probably easiest. Fine.
Now, I'm in the directory
e:\web\thinkspotwebsite\dev
and the following command executes from within that directory from a
command line prompt (in a DOS window):
E:\Web\Thinkspotwebsite\dev>python email_filter.py < test4.txt
and gives me the expected results.
Inside of IDLE I tried (after importing os, of course):
Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> import os, sys
>>> os.chdir(r'e:\web\thinkspotwebsite\dev')
>>> os.path.abspath(os.curdir)
'e:\\web\\thinkspotwebsite\\dev'
>>> os.spawnl(os.P_WAIT, 'python email_filter.py < test4.txt')
Traceback (most recent call last):
File "<pyshell#3>", line 1, in ?
os.spawnl(os.P_WAIT, 'python email_filter.py < test4.txt')
File "E:\PYTHON\PYTHON22\lib\os.py", line 530, in spawnl
return spawnv(mode, file, args)
OSError: [Errno 2] No such file or directory
So, I thought maybe it needed the environment variables. Maybe it
couldn't find the path because I hadn't passed the environment to it???
So I then tried this:
>>> os.spawnle(os.P_WAIT, 'python email_filter.py < test4.txt', os.environ)
Traceback (most recent call last):
File "<pyshell#7>", line 1, in ?
os.spawnle(os.P_WAIT, 'python email_filter.py < test4.txt',
os.environ)
File "E:\PYTHON\PYTHON22\lib\os.py", line 541, in spawnle
return spawnve(mode, file, args[:-1], env)
OSError: [Errno 2] No such file or directory
I've read the docs in the os module, I've looked at my Python 2.1 Bible.
I've been going over my Programming Python (examples of spawnv on pp.
126 - 127) and I can't get this to work.
Here's another try with spawnv:
>>> import os
>>> os.chdir(r'e:\web\thinkspotwebsite\dev')
>>> print os.path.abspath(os.curdir)
e:\web\thinkspotwebsite\dev
>>> os.spawnv(os.P_WAIT, os.curdir, ('python', 'email_filter.py < test4.txt'))
Traceback (most recent call last):
File "<pyshell#4>", line 1, in ?
os.spawnv(os.P_WAIT, os.curdir, ('python', 'email_filter.py <
test4.txt'))
OSError: [Errno 13] Permission denied
>>>
I was trying some other stuff with spawnl and spawnle a bit ago, before
sending this message (I'd saved a draft of what I'd written before) and
was getting that
OSError: [Errno 13] Permission denied
error on some of the other stuff I tried...but my computer crashed and I
don't remember what it was any more.
Can anyone help me out here?
--
Sheila King
http://www.thinkspot.net/sheila/
"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_