subprocess.Popen output to file?
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Sat Apr 7 10:26:07 EDT 2007
In <1175948939.049050.74630 at l77g2000hsb.googlegroups.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
More information about the Python-list
mailing list