Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

This doesn't work as you expect because /proc/<PID>/fd/0 isn't a pipe. If you invoke the sending side with it's stdin connected to a pipe it will work

On the receiving host

nc -l 10000

On the sending host

mkfifo my.fifo
cat >my.fifo &
cat my.fifo | nc remotehost.tld 10000

Now you can

echo "Hello World" >my.fifo
myprog >my.fifo

Note that the cat >my.fifo is required to keep the fifo open otherwise an EOF gets sent and the connection gets closed prematurely. To close the connection down you need to kill the cat process that is holding the fifo open.

share|improve this answer
    
Very helpful! In my case this actually made it easier to communicate with a process because the fifo perms can allow a normal user to affect a sudo'ne script. –  natevw Sep 11 '13 at 1:05
add comment

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

share|improve this answer
    
I corrected my question. But anyway: I tried both /fd/0 and /fd/1. The question remains... –  Geo Jul 15 '12 at 16:27
    
i have tried this, but facing little issue. it does posts the required domain to telnet, but i think it requires some sort of carriage return or new line character, which i am unable to pass to it –  Farhan Aug 13 '13 at 14:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.