What happens to -i ?
Wojtek Walczak
gminick at hacker.pl
Sun Feb 9 12:14:54 EST 2003
Dnia Sun, 09 Feb 2003 16:42:13 -0000, Lee Harr napisał(a):
> I am trying to determine if a script has been run with
> the -i flag.
[...]
> What happens to -i ?
That '-i' lies in the argv of python process not in argv of dashi.py
> How can I tell if -i was specified?
Here you're (this solution is /proc filesystem dependent):
---
import os, sys
try:
path = "/proc/%d/cmdline" % (os.getpid())
r = open(path, "r")
cmdline = r.read()
r.close()
if '-i' in cmdline: #!!! i assume you're using 2.3alpha1 ;]
print "-i is there"
else:
print "there's no -i"
except:
print sys.exc_info()[1]
sys.exit()
---
% python py.py
there's no -i
% python -i py.py
-i is there
>>>
% _
HTH.
--
[ ] gminick (at) underground.org.pl http://gminick.linuxsecurity.pl/ [ ]
[ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ]
More information about the Python-list
mailing list