By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,199 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,199 IT Pros & Developers. It's quick & easy.

Is it possible to get whole commandline include redirection.., etc

P: n/a
Can I get whole commandline not only argument list.

1. When I command like this
$ a.py filename
2. sys.argv is returns only argument list
['a.py']

Is there a way to find out 'redirection' information.

thank you for reading this

Jan 12 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Friday, Jan 12th 2007 at 15:11 -0800, quoth po*******@gmail.com:

=>Can I get whole commandline not only argument list.
=>
=>1. When I command like this
= $ a.py filename
=>2. sys.argv is returns only argument list
= ['a.py']
=>
=>Is there a way to find out 'redirection' information.

As a new person to python, I'm going to go out on a limb and declare this
to not be a python question and to be a Unix question. If you're running
under Windoze then my answer may not be valid since, as you can see, I
only recently learned how to spell it.

When any Unix commandline is handed to a shell, all pipes and redirections
are processed by that shell so that the various IO channels for the
command are defined to point to the desired files before the command is
even started. Only after that setup has occured is the desired command
even started. There are books on the subject and this is not the correct
forum to explain it all, but the docs to read that will leave you with no
hint of idiomatic usage are all in section 2: fork, exec, open, close, dup
and pipe (plus a few others not germain here also).

--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
Jan 12 '07 #2

P: n/a
Thanks Steven.

Jan 14 '07 #3

P: n/a
po*******@gmail.com wrote:
Can I get whole commandline not only argument list.

1. When I command like this
$ a.py filename
2. sys.argv is returns only argument list
['a.py']

Is there a way to find out 'redirection' information.
It's not possible to find the exact command line redirections.

However, you can tell whether a standard I/O stream has been redirected
or not (kind of) using isattr attribute. For instance,
sys.stdin.isatty() returns 1 when it's not being redirected. It's not
exact, though. It's possible to redirect to a device that is a tty,
and sometimes standard I/O streams will not be ttys even without
redirection, such as when run by a script with redirection. (It
shouldn't be a problem, since the main use case is to check whether the
program should run in interactive mode or not.)
Carl Banks

Jan 14 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.