Redirect output on script

Discussion in 'Python' started by glenn.pringle@gmail.com, Sep 17, 2009.

  1. Guest

    I would like to redirect the output of the command below to another
    file
    type test.txt > test.bak

    I'm trying to do this as part of a python script running on Windows
    XP.

    I'm using os.system('type "filepath.txt > filepath.bak"') but nothing
    is happening.

    I was wondering if somebody could enlighten me.



    Thanks,


    Glenn Pringle
    , Sep 17, 2009
    #1
    1. Advertising

  2. MRAB Guest

    wrote:
    > I would like to redirect the output of the command below to another
    > file
    > type test.txt > test.bak
    >
    > I'm trying to do this as part of a python script running on Windows
    > XP.
    >
    > I'm using os.system('type "filepath.txt > filepath.bak"') but nothing
    > is happening.
    >

    Try:

    os.system('type "filepath.txt" > "filepath.bak"')

    or just:

    os.system('type filepath.txt > filepath.bak')

    > I was wondering if somebody could enlighten me.
    >
    MRAB, Sep 17, 2009
    #2
    1. Advertising

  3. Hi!

    import os
    os.system('cmd /c type L:\\source.fic >L:\\destination.txt')

    @-salutations
    --
    Michel Claveau
    Michel Claveau - MVP, Sep 17, 2009
    #3
  4. Chris Rebert Guest

    On Thu, Sep 17, 2009 at 3:58 AM,
    <> wrote:
    > I would like to redirect the output of the command below to another
    > file
    > type test.txt > test.bak
    >
    > I'm trying to do this as part of a python script running on Windows
    > XP.
    >
    > I'm using os.system('type "filepath.txt > filepath.bak"') but nothing
    > is happening.
    >
    > I was wondering if somebody could enlighten me.


    Using the handy-dandy subprocess module:

    bak = file('filepath.bak', 'w')
    subprocess.call(['type', 'filepath.txt'], stdout=bak)

    Cheers,
    Chris
    --
    http://blog.rebertia.com
    Chris Rebert, Sep 17, 2009
    #4
    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. =?Utf-8?B?VHJveQ==?=

    Response.redirect does not redirect from .aspx page

    =?Utf-8?B?VHJveQ==?=, Oct 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,229
    Srowe1975
    Oct 15, 2008
  2. Rajat
    Replies:
    3
    Views:
    688
    Jorgen Grahn
    Jan 8, 2010
  3. Sal
    Replies:
    1
    Views:
    398
  4. Ron Howard
    Replies:
    2
    Views:
    514
    Ron Howard
    Aug 11, 2004
  5. Replies:
    4
    Views:
    181
    Josef Moellers
    Oct 27, 2007
Loading...

Share This Page