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