[英]Run shell script in python with specific parameters
I wish to run a script, lets call it api.sh .我想运行一个脚本,我们称之为api.sh 。 The script takes various arguments,
该脚本采用各种参数,
and it is going to create a new json file, eg data_2.json .它将创建一个新的 json 文件,例如data_2.json 。
When I run this in terminal I use the following command:当我在终端中运行它时,我使用以下命令:
./api.sh -t token -r rules.json -s data.json > data_2.json
However, I wish to run this command line in Python.但是,我希望在 Python 中运行此命令行。 Any suggestions are appreciated.
任何建议表示赞赏。
Thanks,谢谢,
Does this test.py
work:这个
test.py
工作吗:
import subprocess
from subprocess import Popen
path_to_output_file = 'data_2.json'
myoutput = open(path_to_output_file,'w+')
p = Popen(["./api.sh", "-t" , "token", "-r", "rules.json", "-s", "data.json"], stdout=myoutput, stderr=subprocess.PIPE, universal_newlines=True)
output, errors = p.communicate()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.