tags:

views:

48

answers:

2

Hey,

I want to replace the current process with a new one using os.execv, this works fine unless you don't have any arguments.

How can I call this even if I don't have an arguments to pass to the process I want to launch ?

# Works fine, unless the arguments tuple wouldn't exist or be empty
os.execv('process.exe', ('arg1', 'arg2'))
+1  A: 

This works for me

os.execv('process',())

are you sure your process work without arguments?

Or try execl

os.execl('process')
Vinko Vrsalovic
That will give an error that the tuple is empty for me (In python 2.7), and yes I know it works without arguments, it's a py2exe package.
Xeross
I'm using 2.5 so that may be the issue. Have you tried with execl() then?
Vinko Vrsalovic
Seems that execl uses execv behind the scenes: http://pastebin.com/W1YKpxe7
Xeross
Very strange that 2.7 behaves so differently than 2.5, maybe it's an OS difference, you seem to be running Windows, I've tested on Linux
Vinko Vrsalovic
It's indeed a version issue, I just compiled 2.7 on Linux and it behaves like you mention. Although os.execv('process', ['']) on Linux works, on Windows it crashes the interpreter
Vinko Vrsalovic
And I managed to get it to work with os.execv("C:\windows\system32\calc.exe", ["x"])
Vinko Vrsalovic
Python 2.6 behaves like 2.5 in this respect
Vinko Vrsalovic
Guess I'll have to ask on IRC then, I don't want to use dummy arguments as it's not a clean solution.
Xeross
Do report what you find! I'm fairly curious.
Vinko Vrsalovic
+1  A: 

Okay, after asking on IRC they pointed out why it works this way.

The first argument (arg0) is normally the filename of what you're executing (sys.argv[0] for example), so the first argument should always be the filename.

This explains why the arguments aren't optional, on IRC they said that arg0 is what the app will think its name is.

Xeross