代码:
with open ('Client.txt','r') as Client_Name:
for Client in Client_Name:
out = subprocess.Popen(['script.sh', '-byclient', Client], stdout=subprocess.PIPE)
outputstring = out.communicate()
print (outputstring)
此代码未提供输出,我想将Client.txt
文件中的客户端名称传递给script.sh
。请提出任何建议。
答案 0 :(得分:0)
将您的名称传递给脚本的代码似乎是正确的,但E:\Work\test>elementor https://angularjs.org
Creating protractor configuration file
Starting protractor
Running command: [node C:\Users\Vikash777\AppData\Roaming\npm\node_modules\elementor\node_modules\protractor\built\cli.js --elementExplorer true --debuggerServerPort 6969 C:\Users\VIKASH~1\AppData\Local\Temp\protractor-conf117814-7776-q2aq5m.jdozu84cxr]
E:\Work\test>
实际上会返回communicate
,tuple
。
您可能还想将(stdout_data, stderr_data)
传递给universal_newlines=True
来解码输出。试试这个:
Popen
或者,如果您想实时打印输出:
out = subprocess.Popen(['script.sh', '-byclient', Client],
stdout=subprocess.PIPE,
universal_newlines=True)
out.wait() # wait until the script has finished
stdout_data, stderr_data = out.communicate()
print(stdout_data)