Linux – Write to stdin of a running process using pipe

linuxprocessstdin

I am in a similar situation as in this post
But I couln't get the solution provided there to work in my situation as the answer seems related to that question only.

In particular, I couldnt understand what was the purpose of

cat my.fifo | nc remotehost.tld 10000

In my case, I have a process running and waiting for input. how can I send input to that process using named pipes?

I've tried echo 'h' > /proc/PID/fd/0 it just displays 'h' on the process' window.

Best Answer

Just ignore the lines containing nc, the OP in this questions wants to use it to transfer data over the network via nc.

That leaves you with:

mkfifo yourfifo
cat > yourfifo &
mypid=$!
yourprogram < yourfifo

Now you can sent data to your program with

echo "Hello World" > yourfifo

If you are done, terminate your program, issue the command kill $mypid to get rid of the dummy process to keep the FIFO open and rm yourfifo to get rid of the named pipe.