python - calling a shell script with option and argument and get output -
i trying call shell script option , argument , output. not work expected. please help. not familiar python.
import os import subprocess jpsop=os.popen("jps |grep main|awk '{print $1}'").read() print jpsop #print jpsop.partition(' ')[2] pid in jpsop.split(): print pid subprocess.popen(['/home/muthu/downloads/check_jstat.sh', '-p' + pid]) print output # os.system('/home/muthu/downloads/check_jstat.sh')
i have tried;
output=subprocess.popen(['/home/muthu/downloads/check_jstat.sh', '-p', str(pid)])
i used sth in code, invoke commands , bash scripts, cmd can "my_script.sh -p sth". check if bash script have correct permissions ;) (chmod u+x script.sh). hope can helpfull.
def run_cmd(self,cmd): """ :param cmd: command invoke :return: status of command """ try: result = subprocess.check_output(cmd, stderr=subprocess.stdout, universal_newlines=true, shell=true) except subprocess.calledprocesserror grepexc: return {"status": "error", "code" : grepexc.returncode, "output" : grepexc.output} return {"status": "ok", "code": 0, "output" : result}
Comments
Post a Comment