Accessing shell output from HTTP
Brendon Wickham
brendon.wickham at gmail.com
Mon Mar 30 08:19:25 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, as I understand
it, it's an asynchronous call to shell via an HTTP thread) 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 (the script, called from
a web browser, is supposed to capture the output into the variable) 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/20090330/d20d6135/attachment.html>
More information about the Python-list
mailing list