Write to the stdin of a running process with the same effect/behaviour of directly writing

Geo asked:

This post answers only partial my question. My problem is that writing to the stdin of the running process using the FD of process on the /proc filesystem does not have the same effect.

Problem:

  1. start nc to listen on port 10000 (this process is called further nc 1)

    nc -l 10000
    
  2. start another nc to send chars to the listening nc (this will be nc 2)

    nc localhost 10000
    
  3. Write to the stdin on the nc 2

    echo "some chars here" >> /proc/[PID-nc-2]/fd/0
    

the problem: “some chars here” do not get to the listening nc (nc 1), BUT are shown on the console of the nc 2.

Question:
why and is it possible to make this working?

My answer:


As stated in the answer to the post you linked, you need to write to /proc/pid/fd/0, not /proc/pid/fd/1.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.