Is it possible to get whole commandline include redirection.., etc
pavlovevidence at gmail.com
Sun Jan 14 21:04:57 CET 2007
postindex at 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
> 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.)
More information about the Python-list