python os.execvp() trying to display mysql tables gives 1049 error - Unknown database error.
- by Hemanth Murthy
I have a question related to mysql and python.
This command works on the shell, but not when I use os.execvp()
$./mysql -D test -e "show tables"
+----------------+
| Tables_in_test |
+----------------+
| sample |
+----------------+
The corresponding piece of code in python would be
def execute():
args = []
args.extend(sys.argv[1:])
args.extend([MYSQL, '-D test -e "show tables"'])
print args
os.execvp(args[0], args)
child_pid = os.fork()
if child_pid == 0:
os.execvp(args[0], args)
else:
os.wait()
The output of this is:
[./mysql', '-D test -e "show tables"']
ERROR 1049 (42000): Unknown database ' test -e "show tables"'
I am not sure if this is a problem with the python syntax or not. Also, the same command works with os.system() call.
os.system(MYSQL + ' -D test -e "show tables"')
Please let me know how to get this working.
Thanks,
Hemanth