python subprocess模塊使用例子

# python subprocess模塊使用例子
import subprocess

mysql_login = ["mysql", "-h", "localhost", "-u", "root", "-p", "1234"]
mysql_cmd = mysql_login + ["-e", "show databases;use mysql;show tables;"]
p = subprocess.Popen(mysql_cmd, 
                     stdout=subprcess.Pipe,
                     stderr=subprcess.Pipe,
                     )
stdout, stderr = p.communicate() #怕輸出太多,使用內存
print stdout
相關文章
相關標籤/搜索