What causes subprocess.call to output blank file when attempting db export with mysqldump?
Posted
by caldazar
on Stack Overflow
See other posts from Stack Overflow
or by caldazar
Published on 2009-12-30T07:41:20Z
Indexed on
2010/03/23
12:03 UTC
Read the original article
Hit count: 282
I am having some problems using subprocess.call to export a database using mysqldump. I'm using Python 3.1 installed on Windows 7.
from time import gmtime, strftime
import subprocess
DumpDir = "c:/apps/sqlbackup/";
DumpFile = "mysqldump-" + strftime("%Y-%m-%d-%H-%M-%S", gmtime()) + ".sql";
params = [r"mysqldump --user root --password=mypassword --force --flush-privileges --compress --comments mydatabase --result-file=" + DumpDir + DumpFile];
subprocess.call(params, shell=True);
The above code causes a blank file to be created in the DumpDir.
I've tried getting python to print the command so I can test it via the CMD prompt using:
print(subprocess.list2cmdline(params));
If I paste the output to the CMD prompt and execute it, everything works fine.
Any ideas?
I'm new to Python, so I am sure the answer is simple but I've tried so many variations to get this working that I just can't figure this out.
© Stack Overflow or respective owner