Redirect output on script

G

glenn.pringle

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
 
M

MRAB

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')
 
M

Michel Claveau - MVP

Hi!

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

@-salutations
 
C

Chris Rebert

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top