Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > subprocess.Popen output to file?

Reply
Thread Tools

subprocess.Popen output to file?

 
 
John Pye
Guest
Posts: n/a
 
      04-07-2007
Hi all

I am trying to set up a python script to manage backups of a mysql
database the 'right way' using pipes. I want to send the output of the
'mysqldump' command to a file. Using a normal shell script this would
be easy using a ">" operator. What is the efficient and best way to do
this using pure python, bearing in mind that it will be too much data
to keep in memory? I presume using the subprocess module, but how to
get the output to a file? It's not really documented, AFAICS.

Cheers
JP

 
Reply With Quote
 
 
 
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      04-07-2007
In <. com>, John Pye wrote:

> I am trying to set up a python script to manage backups of a mysql
> database the 'right way' using pipes. I want to send the output of the
> 'mysqldump' command to a file. Using a normal shell script this would
> be easy using a ">" operator. What is the efficient and best way to do
> this using pure python, bearing in mind that it will be too much data
> to keep in memory? I presume using the subprocess module, but how to
> get the output to a file? It's not really documented, AFAICS.


I think it is documented, that's what the `stderr` and `stdout` arguments
are used for. Untested:

f = open('dump.txt', 'wb')
p = Popen(('mysqldump', '--option', '--another-option'), stdout=f)
r = p.wait()

Ciao,
Marc 'BlackJack' Rintsch
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange problem - page output contains output from another request Paul ASP .Net 1 04-10-2007 03:41 PM
parse output screen ok but cant get desired output new file! chuck amadi Python 1 06-23-2004 02:16 PM
Sony Precision Cinema Progressive Output vs Component 480p Output Otto Pylot DVD Video 1 04-18-2004 09:49 PM
Is Fuji S3000 3.2m/pixel output, or 6 m/pixel interpolated output? Peter H Digital Photography 43 12-04-2003 02:35 PM
Output / Debug window output bug? John Bentley ASP .Net 0 09-10-2003 07:38 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57