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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • postindex@gmail.com

    #1

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

    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

  • Steven W. Orr

    #2
    Re: Is it possible to get whole commandline include redirection.., etc

    On Friday, Jan 12th 2007 at 15:11 -0800, quoth postindex@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

    Comment

    • postindex@gmail.com

      #3
      Re: Is it possible to get whole commandline include redirection.., etc

      Thanks Steven.

      Comment

      • Carl Banks

        #4
        Re: Is it possible to get whole commandline include redirection.., etc

        postindex@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.isatt y() 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

        Comment

        Working...