Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sending command to process using /proc

I have an application which runs as a process on a ubuntu server. This application has command line gui which allows me to type in a command, then press enter and the command runs. I am able to script the determination of the process id. I then script the following to send it a command:

# echo "command" > /proc/<PROCESSID>/fd/0

I have tried variations of

# echo "command" > /proc/<PROCESSID>/fd/0

# echo -e "command\r" > /proc/<PROCESSID>/fd/0

# echo -e "command\c" > /proc/<PROCESSID>/fd/0
# echo -e "\015" > /proc/<PROCESSID>/fd/0

I know the program is getting the command but does not execute it. I suspect this is because I am not physically pressing enter and possibly the command line is expecting this. Can someone advise me on how I am using this incorrectly or a better option?

like image 490
RandyMorris Avatar asked Oct 02 '10 13:10

RandyMorris


1 Answers

You can't do that. /proc/fd/0 is (usually) not a pipe which you can write to and give the process input.

What you need to do, is invoke the process with its stdin coming from something that IS a pipe (or socket etc) so that you can write stuff into it.

A named pipe MAY work here (see mknod(1) or mkfifo(3) ).

Otherwise, you'll need a control program which sits in front of it and uses a pair of pipes to talk to it.

like image 105
MarkR Avatar answered Sep 18 '22 06:09

MarkR