[python-win32] Spawnv problem

Tim Roberts timr at probo.com
Wed Feb 1 00:00:38 CET 2006


On Tue, 31 Jan 2006 15:08:24 -0000,"Frank Peacock"
<fepeacock at bulldoghome.com> wrote:

>I cannot seem to spawn a subprocess. The subprocess does not seem to be run.
>
>Attached are my two files. There is a main.py file and a subprocess.py file. They simpy print their names.
>
>Can anyone suggest a reason?
>


Your code works properly for me, once I adjust the paths.  You do have a
backslash problem in there, in that your path to Python needs another
backslash after the c:, but it will accidentally work because \p is not
a recognized escape character.


C:\tmp>type main.py
# Main script
import os
print("main")
os.spawnv(os.P_WAIT,
'c:\\apps\\python24\\python.exe',('python.exe','c:\\tmp\\subprocess.py'))
print("exit")

C:\tmp>type subprocess.py
print("subprocess")

C:\tmp>main.py
main
subprocess
exit

C:\tmp>

There is a standard module called subprocess, but that shouldn't affect
this.

You're sure that your subprocess.py script lives in the root of your
hard disk?

You may not be aware that "print" is a statement, not a function.  Those
parentheses aren't really doing what you think they're doing.  This does
what you expect:
    print("main")
because a single item in parentheses is taken to be the same as the
item.  But this:
    print("a","b")
does something quite different.  That creates a two-element tuple and
prints that.

C:\tmp>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("a","b")
('a', 'b')
>>> print "a","b"
a b
>>>

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-win32 mailing list