发送多个字符串我发送字符串Router_Status [路由器] =“ON”由父代码来新工艺如何通过标准输入Python中
proc[Router] = subprocess.Popen([sys.executable, os.getcwd() + '/'
+ Router + '.py', Router,
json.dumps(graph),
json.dumps(As_numbers_dict)],
shell=False, stderr=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
proc[Router].stdin.write(bytes(Router_Status[Router],
encoding='utf-8') + b'\n')
和子进程
Router_Status[Router]=sys.stdin.readline().strip()
path = os.path.expanduser('~' + '/BGP_Routers/' + Router)
with open(path + '/Router_Status.txt', 'w') as f:
f.write(Router_Status[Router])
但它不起作用! 然后我通过第二串Router_Status [路由器] = 'OFF' 的过程由 PROC [路由器] .stdin.write(字节(Router_Status [路由器],编码= 'UTF-8')
proc[Router].stdin.flush()
它仍然没有做任何事情
不工作怎么样?小孩呆住了吗?你在你的父进程中使用'proc [Router] .wait()'还是一次退出? –
我的子进程有一些无限循环子进程,直到子进程接收到新的字符串='OFF'。我想发送两个stdin。在我的子进程中编写并阅读它们。它也不会生成文件,也不会在文件中写入'ON'或'OFF'。文件路径是正确的。 –
你尝试过'proc [Router] .stdin.close()'?只是为了看看它在做什么 –