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'))
These three variants can resolve the problem:
cmd = '/usr/bin/vi'
os.execv(cmd, (' ',))
os.execv(cmd, [' '])
os.execl(cmd, '')
Usually, the first parameter of an argument list (sys.argv) is the command which had been used to invoke the application. So it is better to use one of those:
cmd = '/usr/bin/vi'
os.execv(cmd, (cmd,))
os.execv(cmd, [cmd])
os.execl(cmd, cmd)
os.exec* documentation on python.org
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.
This works for me
os.execv('process',())
are you sure your process
work without arguments?
Or try execl
os.execl('process')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With