This is because, the
echo "j" > /proc/5440/fd/0
in fact, is something like this (the pts
number can be differ in your case):
echo "j" > /dev/pts/2
Explanation:
I doesn't have ranger
, so I were running vim
- the no difference here, mechanism the same. Then, I found out the vim
's PID - 6466
and looked into the /proc/6466/fd
directory:
$ ls -l /proc/6466/fd
lrwx------ 1 minimax minimax 64 Nov 20 01:20 0 -> /dev/pts/2
lrwx------ 1 minimax minimax 64 Nov 20 01:20 1 -> /dev/pts/2
lrwx------ 1 minimax minimax 64 Nov 20 01:20 2 -> /dev/pts/2
All file descriptors of the vim
's process are symbolic links to the current terminal. So, the echo "j" > /proc/5440/fd/0
converts to the echo "j" > /dev/pts/2
, which means literally: "Redirect the output of the echo
command to the terminal file /dev/pts/2
". Not to the stdin of the vim
's process.
As far as I know, the terminal can get input only from keyboard and there is no way passing input to it somehow else. So, you need search for another method, to passing commands to the working process.
Also, keep in mind, that the echo
adds the newline to its output, that is causing printing j
by stairs, in your case. If change it to the echo -n j
, the output will be jjj
- without newlines.
/proc/5440/fd/1
is not thestdin
, it is thestdout
. The file descriptor of thestdin
is 0 or/proc/5440/fd/0
./proc/5440/fd/0
.