[英]How to supply raw_input to a python program running on a terminal window in linux from a different terminal, all running on same UNIX
I have 2 terminals open in a unix system. 我在Unix系统中有2个终端。 On one terminal I have a python program running that accepts raw_input, and I want to supply this raw_input from the other terminal that is not running this python program.
在一个终端上,我正在运行一个接受raw_input的python程序,并且我想从另一个未在运行该python程序的终端上提供此raw_input。
I tried something like: 我尝试了类似的东西:
echo 3 > /dev/pts/172 回声3> / dev / pts / 172
But this is just printing the number 3 on the terminal but not really doing the function of giving "3" and ENTER key from keyboard 但这只是在终端上打印数字3,而实际上并没有执行通过键盘提供“ 3”和ENTER键的功能
terminal 1 being /dev/pts/252 and terminal running python program being /dev/pts/172 终端1是/ dev / pts / 252,终端运行python程序是/ dev / pts / 172
If the idea is to feed a program remotely, a fairly popular solution is not to use stdin
for input, but to open a pipe
, and have the program listen to the pipe. 如果您的想法是远程馈入程序,那么一个比较流行的解决方案不是使用
stdin
作为输入,而是打开pipe
,让程序监听管道。 You can then open the pipe in another program, and send data to it. 然后,您可以在另一个程序中打开管道,然后向其中发送数据。 If you use
named pipes
, you can even echo
to the pipe. 如果使用
named pipes
,甚至可以echo
到管道。
Sending data to stdin
of another terminal (and, as such, to raw_input), is obviously a dangerous idea, as this would permit executing commands in someone else's terminal. 将数据发送到另一个终端的
stdin
(以及这样的raw_input)显然是一个危险的想法,因为这将允许在其他人的终端中执行命令。
Directing to /proc/script_PID/fd/0
won't work - this is linked to the same device in /dev/pts/. /proc/script_PID/fd/0
到/proc/script_PID/fd/0
无效-这链接到/ dev / pts /中的同一设备。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.