發送多個字符串我發送字符串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()'?只是爲了看看它在做什麼 –