Inspired by another question here, I would like to retrieve the Python interpreter's full command line in a portable way. That is, I want to get the original argv
of the interpreter, not the sys.argv
which excludes options to the interpreter itself (like -m
, -O
, etc.).
sys.flags
tells us which boolean options were set, but it doesn't tell us about -m
arguments, and the set of flags is bound to change over time, creating a maintenance burden.
On Linux you can use procfs to retrieve the original command line, but this is not portable (and it's sort of gross):
open('/proc/{}/cmdline'.format(os.getpid())).read().split('\0')