Question: spawn and redirection

Discussion in 'Python' started by Ladvánszky Károly, Feb 13, 2004.

  1. On Windows, what is the proper way to spawn an executable and redirect its
    stdout and stderr.
    Thanks for any help,

    Károly
     
    Ladvánszky Károly, Feb 13, 2004
    #1
    1. Advertising

  2. I'd like to redirect the program output into a file.

    "Peter Hansen" <> az alábbiakat írta a következo
    hírüzenetben: ...
    > "Ladvánszky Károly" wrote:
    > >
    > > On Windows, what is the proper way to spawn an executable and redirect

    its
    > > stdout and stderr.

    >
    > Redirect them where? The answer might well be different (e.g. os.system

    vs.
    > os.popen) if you are redirecting them to a file versus redirecting them

    back
    > to the calling program.
    >
    > -Peter
     
    Ladvánszky Károly, Feb 13, 2004
    #2
    1. Advertising

  3. Ladvánszky Károly

    Peter Hansen Guest

    "Ladvánszky Károly" wrote:
    >
    > On Windows, what is the proper way to spawn an executable and redirect its
    > stdout and stderr.


    Redirect them where? The answer might well be different (e.g. os.system vs.
    os.popen) if you are redirecting them to a file versus redirecting them back
    to the calling program.

    -Peter
     
    Peter Hansen, Feb 13, 2004
    #3
  4. Ladvánszky Károly

    anton muhin Guest

    Ladvánszky Károly wrote:
    > On Windows, what is the proper way to spawn an executable and redirect its
    > stdout and stderr.
    > Thanks for any help,
    >
    > Károly
    >
    >



    os.spawnv(os.P_NOWAIT, r'c:\WINNT\system32\cmd.exe', ('/C dir > dir.txt',))

    does a trick for me.

    regards,
    anton.
     
    anton muhin, Feb 13, 2004
    #4
  5. Ladvánszky Károly

    Peter Hansen Guest

    "Ladvánszky Károly" wrote:
    >
    > I'd like to redirect the program output into a file.


    I'd just us os.system then, as in

    os.system('command >somefile')

    -Peter
     
    Peter Hansen, Feb 13, 2004
    #5
  6. Thanks for your advice. os.system() is not suitable in all cases as it
    always waits for the started process to terminate.

    "Peter Hansen" <> az alábbiakat írta a következo
    hírüzenetben: ...
    > "Ladvánszky Károly" wrote:
    > >
    > > I'd like to redirect the program output into a file.

    >
    > I'd just us os.system then, as in
    >
    > os.system('command >somefile')
    >
    > -Peter
     
    Ladvánszky Károly, Feb 13, 2004
    #6
  7. Ladvánszky Károly

    Peter Hansen Guest

    "Ladvánszky Károly" wrote:
    >
    > Thanks for your advice. os.system() is not suitable in all cases as it
    > always waits for the started process to terminate.
    >
    > "Peter Hansen" <> az alábbiakat írta a következo
    > hírüzenetben: ...
    > > "Ladvánszky Károly" wrote:
    > > >
    > > > I'd like to redirect the program output into a file.

    > >
    > > I'd just us os.system then, as in
    > >
    > > os.system('command >somefile')


    On Windows, you would simply to this instead then, I believe:

    os.system('start command >somefile')

    -Peter
     
    Peter Hansen, Feb 13, 2004
    #7
    1. Advertising

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. Donn Cave
    Replies:
    1
    Views:
    552
    TH Lim
    Jul 10, 2003
  2. Lingyun Yang
    Replies:
    4
    Views:
    11,854
    Keith Dart
    Dec 16, 2004
  3. Derek Basch
    Replies:
    2
    Views:
    1,314
    Donn Cave
    Jan 21, 2005
  4. Ed Hames
    Replies:
    0
    Views:
    388
    Ed Hames
    Apr 16, 2008
  5. Edgardo Hames
    Replies:
    1
    Views:
    364
    Ed Hames
    May 6, 2008
Loading...

Share This Page