python os.execvp() trying to display mysql tables gives 1049 error - Unknown database error.

Posted by Hemanth Murthy on Stack Overflow See other posts from Stack Overflow or by Hemanth Murthy
Published on 2010-04-16T15:23:09Z Indexed on 2010/04/17 2:03 UTC
Read the original article Hit count: 308

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about python

Related posts about mysql