Reputation: 11
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
Upvotes: 0
Views: 182
Reputation: 5440
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/.
Upvotes: 1