on-internet
← Community

mysql via subprocess doesn't work

Stack Overflow ·

import os import subprocess cmdline = ['mysql -u"username" -p"password" < query.sql'] p = subprocess.Popen(cmdline,stdout=subprocess.PIPE) stdout,stderr = p.communicate() retcode = p.wait() That's my code to connect to mysql and execute query.sql. Looks good to me, but it doesn't work and the bad thing is that I don't get any error message at all. retcode is 1 and from stdout, stderr I only get the mysql standard text "Usage mysql [OPTIONS] [Database] ..." so I thought my syntax is wrong. But it's not. I tested the line of code in terminal and it works. Does python have a problem to execute th

Comments

Sign in or sign up to comment and upvote.

No comments yet.