Python 对于子进程不工作的循环

Python 对于子进程不工作的循环,python,subprocess,popen,Python,Subprocess,Popen,当我将子流程与for循环一起使用时。输出为空。但是如果我只需要输入一个客户机名称并运行脚本,输出就可以了。如何为不同的客户机循环它。有什么建议吗???谢谢 with open('Client.txt','r') as Client_Name: for Client in Client_Name.readlines(): f=file('data_output','w') p1 = subprocess.Popen(['nbcommand', '-bycli

当我将子流程与for循环一起使用时。输出为空。但是如果我只需要输入一个客户机名称并运行脚本,输出就可以了。如何为不同的客户机循环它。有什么建议吗???谢谢

with open('Client.txt','r') as Client_Name: 
   for Client in Client_Name.readlines(): 
       f=file('data_output','w') 
       p1 = subprocess.Popen(['nbcommand', '-byclient', Client], stdout=f, stderr=subprocess.PIPE)
       p1.wait() 
       f.close()

当您在Client_Name.readlines()中为Client使用
时,您将得到末尾带有
'\n'
的行。因此,您可以使用
rstrip()
或使用
Client\u Name.read().splitlines()
删除该新行字符,例如:

Client = 'abcd'  
f=file('data_output','w')  
p1 = subprocess.Popen(['nbcommand', '-byclient', Client], stdout=f,stderr=subprocess.PIPE)
p1.wait()  
f.close()
或:


当您在Client_Name.readlines()中为Client使用
时,您将得到末尾带有
'\n'
的行。因此,您可以使用
rstrip()
或使用
Client\u Name.read().splitlines()
删除该新行字符,例如:

Client = 'abcd'  
f=file('data_output','w')  
p1 = subprocess.Popen(['nbcommand', '-byclient', Client], stdout=f,stderr=subprocess.PIPE)
p1.wait()  
f.close()
或:


考虑使用第二个文件的上下文管理器。例如,将open('data_output','r')作为f:考虑对第二个文件使用上下文管理器。例如使用open('data_output','r')作为f:lay to help:-)lay to help:-)
with open('Client.txt','r') as Client_Name: 
    for Client in Client_Name.readlines(): 
        Client = Client.rstrip()
        # rest of code