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

P

postindex

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
 
S

Steven W. Orr

On Friday, Jan 12th 2007 at 15:11 -0800, quoth (e-mail address removed):

=>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
 
C

Carl Banks

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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top