0

I want to write a wrapper script around the mysql cli client. So I can construct the mysql cli flags to be used based on some logic.

my question is:

How would I execute the mysql client so that the user can interact with it. (stdout,stdin forwarded etc)?

jmail
  • 5,718
  • 3
  • 18
  • 34
wjimenez5271
  • 1,637
  • 2
  • 15
  • 23

1 Answers1

1

Just build your list of arguments and use the subprocess module to launch MySQL

import subprocess

args = ['-u', 'wjimenez5271', '-p']
subprocess.call('mysql', args)
print('done')

This will launch mysql -u wjimenez5271 -p, handing over control until the process terminates, then python will resume and print "done".

Peter Gibson
  • 18,055
  • 6
  • 57
  • 63