Run shell command with input redirections from python 2.4?

前端 未结 3 1892
渐次进展
渐次进展 2021-02-13 18:50

What I\'d like to achieve is the launch of the following shell command:

mysql -h hostAddress -u userName -p userPassword 
databaseName < fileName
3条回答
  •  粉色の甜心
    2021-02-13 19:31

    You have to feed the file into mysql stdin by yourself. This should do it.

    import subprocess
    ...
    filename = ...
    cmd = ["mysql", "-h", ip, "-u", mysqlUser, dbName]
    f = open(filename)
    subprocess.call(cmd, stdin=f)
    

提交回复
热议问题