Accessing shell output from HTTP
Brendon Wickham
brendon.wickham at gmail.com
Sun Mar 29 07:53:38 EDT 2009
Hi there,
I would like users of my web application to be able to download a backup
file of a database (using* *MySQL's *mysqldump* command).
My strategy is to use *zipfile* to create a zip file object (with the *
mysqldump* output as the contents of the zipped file) and then use *
sys.stdout* to send the zip file object to the user as a file for them
download.
The zipping bit and file delivery is all sorted. Getting the output from *
mysqldump* is my problem and I'm not even sure (given that I'm calling shell
via an HTTP thread/process) it is even possible.
This is as far as I've got:
import subprocess as sp
p1 = sp.Popen('mysqldump --opt
--user=[username]--password=[password]
[databasename]',stdout=sp.PIPE,shell=True)
backupfile=p1.communicate()[0]
If I type the above into a Python prompt and print *backupfile* I will get
the expected result, but when I'm going through CGI nothing is being
returned by communicate().
Is this possible? Or am I barking up the wrong tree?
Cheers,
Brendon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090329/6a7e90c5/attachment.html>
More information about the Python-list
mailing list