7
我知道我可以在python
像獲取進程的stdin
使用子:如何通過進程ID獲取進程的stdin?
import subprocess
f = subprocess.Popen('python example.py',stdin=subprocess.PIPE)
f.stdin.write('some thing')
,但我只想知道我想寫的PID進程的stdin
我怎麼能做到這一點?
我知道我可以在python
像獲取進程的stdin
使用子:如何通過進程ID獲取進程的stdin?
import subprocess
f = subprocess.Popen('python example.py',stdin=subprocess.PIPE)
f.stdin.write('some thing')
,但我只想知道我想寫的PID進程的stdin
我怎麼能做到這一點?
簡單地寫/proc/PID/fd/1
:
import os.path
pid = os.getpid() # Replace your PID here - writing to your own process is boring
with open(os.path.join('/proc', str(pid), 'fd', '1'), 'a') as stdin:
stdin.write('Hello there\n')
你想劫持另一個進程的標準輸入?這不是一件很好的事情... –
是的,我想寫一些someting到其他進程的標準輸入 – timger
你想要什麼機器? – 0x90