views:

333

answers:

5

I just noticed that my old codes written in python 2.5 does not work now. I am in python 2.6 btw.

>>> os.spawnl(os.P_NOWAIT,"setup.exe")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python26\lib\os.py", line 612, in spawnl
    return spawnv(mode, file, args)
OSError: [Errno 22] Invalid argument
>>>

Any clue? or do you have any working sample of os.spawn* with NOWAIT option.

Update:

Even I put full path in os.spawnl(), Its still error.

+3  A: 

I think its recommended to use the subprocess module these days rather than the os.spawn* functions. (I can't reproduce your problem, but I'm not on windows).

thrope
+6  A: 

thrope is right about subprocess being preferred. But the spawn* stuff is still there in 2.6. In fact, you can see that in your error message. Your first arg seems to be valid. I'd check the second arg, which is the path.

Ewan Todd
I would check the arguments as I don't get this error when running on a OS/machine with no setup.exe
Mark
I have setup.exe on same folder, I think I am sure.
S.Mark
but I dont have anything to pass setup.exe because Its just invoking installer. even I put blank string "", its not working.
S.Mark
Maybe the current working directory isn't in the environment's search path? But that stuff is beyond my ken for Windows.
Ewan Todd
Imm, I tested by putting in environment variable, still not working, and this is part of program auto update options, so I think I shouldnt mess up with user's environment variables.
S.Mark
The same error S. Mark describes happened to me, and I've only been able to work around it by using subprocess. Shame.
Brian
+2  A: 

os.spawnl() requires full path to executable, while os.spawnlp() uses PATH environment variable to find it.

Update: Also it's common error to use unescaped backslashes in the path literal (try printing it to see whether it's interpreted right).

Denis Otkidach
still same error even I put full path in os.spawnl()
S.Mark
+2  A: 

A Google search brings up this page about the same problem happening when there is a space in the Python installation path. I couldn't reproduce it here, but maybe it's the problem?

In any case, according to MS documentation this error value (EINVAL) should only be returned if the mode argument is invalid, which isn't the case here.

interjay
thx, but my python is in the `c:\python26`
S.Mark
+3  A: 

Hi All,

I got it work by adding DUMMY parameter finally, a bit funky though

This is not working

os.spawnl(os.P_NOWAIT,"Setup.exe")

This is also not working

os.spawnl(os.P_NOWAIT,"Setup.exe","")

But this is working

os.spawnl(os.P_NOWAIT,"Setup.exe","DUMMY")

Thanks all anyway.

S.Mark