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 = 'abcd'
f=file('data_output','w')
p1 = subprocess.Popen(['nbcommand', '-byclient', Client], stdout=f,stderr=subprocess.PIPE)
p1.wait()
f.close()
当您使用for Client in Client_Name.readlines()
时,您将在最后获得'n'
的行。因此,您要么rstrip()
,要么使用Client_Name.read().splitlines()
来摆脱该新的行字符,例如:
with open('Client.txt','r') as Client_Name:
for Client in Client_Name.read().splitlines():
# rest of code
或:
with open('Client.txt','r') as Client_Name:
for Client in Client_Name.readlines():
Client = Client.rstrip()
# rest of code