Redirecting Python stdout ,stderr and stdin

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jan Knop

    Redirecting Python stdout ,stderr and stdin

    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 ?






  • Alexander Schmolck

    #2
    Re: Redirecting Python stdout ,stderr and stdin

    Jan Knop <nospam@nospam. yes> writes:
    [color=blue]
    > 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 ?[/color]

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

    Comment

    • Serge Orlov

      #3
      Re: Redirecting Python stdout ,stderr and stdin


      "Alexander Schmolck" <a.schmolck@gmx .net> wrote in message news:yfssmke8vl 0.fsf@black132. ex.ac.uk...[color=blue]
      > Jan Knop <nospam@nospam. yes> writes:
      >[color=green]
      > > 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 ?[/color]
      >
      > import sys
      > sys.stdin, sys.stderr, sys.stdout = map(open, 'in.txt err.txt out.txt'.split( ),
      > 'r w w'.split())[/color]

      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


      Comment

      • Alexander Schmolck

        #4
        Re: Redirecting Python stdout ,stderr and stdin

        "Serge Orlov" <sombDELETE@pob ox.ru> writes:
        [color=blue]
        > "Alexander Schmolck" <a.schmolck@gmx .net> wrote in message news:yfssmke8vl 0.fsf@black132. ex.ac.uk...[color=green]
        > > Jan Knop <nospam@nospam. yes> writes:
        > >[color=darkred]
        > > > 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 ?[/color]
        > >
        > > import sys
        > > sys.stdin, sys.stderr, sys.stdout = map(open, 'in.txt err.txt out.txt'.split( ),
        > > 'r w w'.split())[/color]
        >
        > 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")[/color]

        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

        Comment

        • Jan knob

          #5
          Re: Redirecting Python stdout ,stderr and stdin

          On 24 Nov 2003 02:02:50 +0000, Alexander Schmolck <a.schmolck@gmx .net>
          wrote:
          [color=blue]
          >"Serge Orlov" <sombDELETE@pob ox.ru> writes:
          >[color=green]
          >> "Alexander Schmolck" <a.schmolck@gmx .net> wrote in message news:yfssmke8vl 0.fsf@black132. ex.ac.uk...[color=darkred]
          >> > Jan Knop <nospam@nospam. yes> 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())[/color]
          >>
          >> 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")[/color]
          >
          >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[/color]

          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

          Comment

          Working...