python subprocess 模块传参方法
在主进程中写要执行的子进程命令后面跟需要传递的参数方法如下:
child = subprocess.Popen(["python","/opt/src/app/apache-jmeter-2.9/bin/test3.py", name])
print("parent process")
子进程的代码如下:
#!/usr/bin/python
import MySQLdb
import subprocess
import os
import pika
improt sys
def run_jmter(name):
print "start.....runjmeter"
pathjmeter = "/opt/src/app/apache-jmeter-2.9/bin/jmeter.sh"
command = "sh %s -n -t %s -l %s" % (pathjmeter,'/opt/src/app/apache-jmeter-2.9/bin/' + name+'.jmx', '/opt/src/app/apache-jmeter-2.9/bin/'+name+'.jtl')
print "do jmeter"
try:
subprocess.check_call(command, shell=True)
#jtl.file.seek(0)
#return jtl.file.read()
print "success"
except Exception,e:
print Exception,":",e
if __name__=="__main__":
#name = "kmtest02"
import sys
run_jmter(sys.argv[1])