简体   繁体   中英

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. 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.

I tried something like:

echo 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

terminal 1 being /dev/pts/252 and terminal running python program being /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. 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.

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.

Directing to /proc/script_PID/fd/0 won't work - this is linked to the same device in /dev/pts/.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM