views:

40

answers:

2

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?

Thanks in advanced for the help!

+2  A: 

Without knowing the specifics, you probably need this: expect

ennuikiller
I have read a bit on this, it seems this is the option to use if you are expecting a certain prompt to which you can programmatically respond. Would you still suggest this if there is no such prompt? I try to use as minimal and clean coding as possible but if using another library is the best answer, I will gratefully accept...
RandyMorris
From your comment on the answer above, it seems like you are expecting some sort of prompt: "and a text based command line appears"
ennuikiller
this was very interesting to read, thank you for your comment :D
RandyMorris
+2  A: 

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.

MarkR
you were right, i was sending the text to the interface, not the program. I will need to do as you advised and create a program to act as a proper pipe. thank you.
RandyMorris