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,944
  • 3
  • 21
  • 35
wjimenez5271
  • 2,027
  • 2
  • 17
  • 24

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
  • 19,086
  • 7
  • 60
  • 64