getting command line in python

M

MrSmile

Hi people!
I am looking for a way to get the command line in the script.

Let us say I am in the folder "/tmp" okay!

now from /tmp I execute in the console this:
python /home/tamer/MyApp/MyScript.py

in the app itself, I want to grep the path and the scriptname itself,
like: /home/tamer/MyApp is being somewhere available.


Tamer
 
I

Irmen de Jong

Hi people!
I am looking for a way to get the command line in the script.

Let us say I am in the folder "/tmp" okay!

now from /tmp I execute in the console this:
python /home/tamer/MyApp/MyScript.py

in the app itself, I want to grep the path and the scriptname itself,
like: /home/tamer/MyApp is being somewhere available.


Tamer

sys.argv


Irmen
 
C

Chris Rebert

Hi people!
I am looking for a way to get the command line in the script.

Let us say I am in the folder "/tmp" okay!

now from /tmp I execute in the console this:
python /home/tamer/MyApp/MyScript.py

in the app itself, I want to grep the path and the scriptname itself,
like: /home/tamer/MyApp is being somewhere available.

Under your example conditions:
sys.argv[0] will be "/home/tamer/MyApp/MyScript.py". (A)
os.getcwd() will return "/tmp". (B)

The `os.path` module is also very relevant:
http://docs.python.org/library/os.path.html

Cheers,
Chris
 
C

Cameron Simpson

| I am looking for a way to get the command line in the script.
|
| Let us say I am in the folder "/tmp" okay!
|
| now from /tmp I execute in the console this:
| python /home/tamer/MyApp/MyScript.py
|
| in the app itself, I want to grep the path and the scriptname itself,
| like: /home/tamer/MyApp is being somewhere available.

Have you looked in sys.argv[0]?
--
Cameron Simpson <[email protected]> DoD#743
http://www.cskk.ezoshosting.com/cs/

It is not true that life is one damn thing after another -- it's one damn
thing over and over. - Edna St. Vincent Millay
 
M

MrSmile

Thank you all, that was it that I was searching for you.


Tamer

Am 08.11.2011 23:32, schrieb Cameron Simpson:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top