I want to obtain the true value of the operating system\'s argv[0] in a Python program. Python\'s sys.argv[0] is not this value: it is the name of the Python script being ex
On Linux you can read the contents of /proc/self/cmdline
:
#!/usr/bin/env python
import sys
print sys.argv[0]
f = open('/proc/self/cmdline', 'rb')
cmdline = f.read()
f.close()
print repr(cmdline.split('\x00'))
And the output is:
$ bash
$ exec -a "somestring" python foo.py
foo.py
['somestring', 'foo.py', '']
There seems to be a bug in The exec command replaces the shell closing the terminal session after the interpreter exits. That's the first bash for.bash