Redirecting Python stdout ,stderr and stdin

Discussion in 'Python' started by Jan Knop, Nov 23, 2003.

  1. Jan Knop

    Jan Knop Guest

    Hello

    I am writing a Windows application where I need to redirect stdin,
    stdout and stderr from Python. to my application
    Is it a simple way of do it ?
    Has anyone done it using Winsock ?
     
    Jan Knop, Nov 23, 2003
    #1
    1. Advertisements

  2. Jan Knop <> writes:

    > Hello
    >
    > I am writing a Windows application where I need to redirect stdin,
    > stdout and stderr from Python. to my application
    > Is it a simple way of do it ?


    import sys
    sys.stdin, sys.stderr, sys.stdout = map(open, 'in.txt err.txt out.txt'.split(),
    'r w w'.split())
    'as
     
    Alexander Schmolck, Nov 24, 2003
    #2
    1. Advertisements

  3. Jan Knop

    Serge Orlov Guest

    "Alexander Schmolck" <> wrote in message news:...
    > Jan Knop <> writes:
    >
    > > Hello
    > >
    > > I am writing a Windows application where I need to redirect stdin,
    > > stdout and stderr from Python. to my application
    > > Is it a simple way of do it ?

    >
    > import sys
    > sys.stdin, sys.stderr, sys.stdout = map(open, 'in.txt err.txt out.txt'.split(),
    > 'r w w'.split())


    That is why map should be deprecated asap ;)

    sys.stdin = open("in.txt")
    sys.stdout = open("out.txt","w")
    sys.stderr = open("err.txt","w")

    -- Serge
     
    Serge Orlov, Nov 24, 2003
    #3
  4. "Serge Orlov" <> writes:

    > "Alexander Schmolck" <> wrote in message news:...
    > > Jan Knop <> writes:
    > >
    > > > Hello
    > > >
    > > > I am writing a Windows application where I need to redirect stdin,
    > > > stdout and stderr from Python. to my application
    > > > Is it a simple way of do it ?

    > >
    > > import sys
    > > sys.stdin, sys.stderr, sys.stdout = map(open, 'in.txt err.txt out.txt'.split(),
    > > 'r w w'.split())

    >
    > That is why map should be deprecated asap ;)
    >
    > sys.stdin = open("in.txt")
    > sys.stdout = open("out.txt","w")
    > sys.stderr = open("err.txt","w")


    The obfuscation in the above example was intended not to immediately overwhelm
    the OP (who expected having to use some winsock thingy) with simplicitly and
    clarity, but now you've spoilt it.


    'as
     
    Alexander Schmolck, Nov 24, 2003
    #4
  5. Jan Knop

    Jan knob Guest

    On 24 Nov 2003 02:02:50 +0000, Alexander Schmolck <>
    wrote:

    >"Serge Orlov" <> writes:
    >
    >> "Alexander Schmolck" <> wrote in message news:...
    >> > Jan Knop <> writes:
    >> >
    >> > > Hello
    >> > >
    >> > > I am writing a Windows application where I need to redirect stdin,
    >> > > stdout and stderr from Python. to my application
    >> > > Is it a simple way of do it ?
    >> >
    >> > import sys
    >> > sys.stdin, sys.stderr, sys.stdout = map(open, 'in.txt err.txt out.txt'.split(),
    >> > 'r w w'.split())

    >>
    >> That is why map should be deprecated asap ;)
    >>
    >> sys.stdin = open("in.txt")
    >> sys.stdout = open("out.txt","w")
    >> sys.stderr = open("err.txt","w")

    >
    >The obfuscation in the above example was intended not to immediately overwhelm
    >the OP (who expected having to use some winsock thingy) with simplicitly and
    >clarity, but now you've spoilt it.
    >
    >
    >'as


    Hi

    Actually that what I wat in the end is a method for subsclassing the
    python stdio's into my application window. This means that Python runs
    in background with all threes stdio streams redirected .
    This is I believe somehow done in the Komodo program from
    ActiveState
    As far as I have found out You need to define a Input and output
    class and imlement Read Readline , Write and WriteLine method in
    these classes.
    Otherwise it will be necessary to somehow capture the Stdin stdout
    streams from python console and redirect them .

    with regards
    Jan
     
    Jan knob, Nov 24, 2003
    #5
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Landenburer

    redirecting stderr and stdout

    Jon Landenburer, May 12, 2004, in forum: Perl
    Replies:
    1
    Views:
    11,512
    Joe Smith
    May 13, 2004
  2. Matthew Thorley

    Redirecting stdout and stdin

    Matthew Thorley, Mar 4, 2004, in forum: Python
    Replies:
    2
    Views:
    855
    Donn Cave
    Mar 4, 2004
  3. Vincent Touquet
    Replies:
    1
    Views:
    895
    Adrian B.
    Sep 3, 2004
  4. Michael McGarry
    Replies:
    1
    Views:
    863
    Michael Fuhr
    Dec 16, 2004
  5. Martijn Brouwer

    closing stdin, stdout and stderr

    Martijn Brouwer, Dec 26, 2005, in forum: Python
    Replies:
    5
    Views:
    1,424
    Donn Cave
    Dec 27, 2005
  6. Lincoln Yeoh

    Redirecting stderr and stdout to syslog

    Lincoln Yeoh, Aug 5, 2008, in forum: Python
    Replies:
    2
    Views:
    2,572
    Lincoln Yeoh
    Aug 6, 2008
  7. Ian Hobson
    Replies:
    0
    Views:
    920
    Ian Hobson
    Sep 6, 2010
  8. it_says_BALLS_on_your forehead
    Replies:
    2
    Views:
    491
    Joe Smith
    Jan 10, 2006
Loading...