Results 1 to 4 of 4
I have a application that I launch at startup and run the process in the background because I do not need to see its output. It is a type of ...
- 07-01-2007 #1Just Joined!
- Join Date
- Jun 2007
- Posts
- 5
Background Program Input
I have a application that I launch at startup and run the process in the background because I do not need to see its output. It is a type of program that takes over the shell until you quit it (similar to how the MySQL shell takes control) and that is why I run it in the background. What I want to do is write a shell script where I can execute a few commands that I would normally type into this program while it is running on my screen and get the output through the script. Is there a way to pass commands to a background process and get its output? Thanks in advance.
- 07-02-2007 #2
I think I understand your problem. I use a gnu screen seesion in which to run my 'background' processes that require occasional interaction. I start the session in an xterm, which is itself running in Xvfb (X virtual framebuffer). I can then re-attach to the screen session at any time, and type commands into my running application. Using screen, it is also possible to 'stuff' keystrokes and strings into the session or to grab a copy of the session's text screen. I have used this to web-ify the application, arranging a CGI to stuff btes and grab screens for display.
Hope this is something like what you were looking for.
--- rod.Stuff happens. Then stays happened.
- 07-02-2007 #3
screen probably isn't what you're looking for. screen essentially allows you to keep multiple terminals running simultaneously in one window, as well as keep a terminal instance running even when you're not there. But for you, who just wants to background a process, this is probably overkill.
One option (and I just tried this out simply) is to use a FIFO. Check "man fifo" for some detailed info, but a FIFO is essentially a file that, rather than existing on the hard drive, just passes its contents on to whatever is reading from it. So you can communicate with any program by having it read a FIFO, and then writing to the FIFO yourself.
Here's a bit of a sample that I just tried:
See? I made a FIFO, redirected my program's input to be from the FIFO and backgrounded it, then wrote "Test" to the FIFO. And sure enough, "Test" got printed back out.Code:alex@danu ~/test/bash $ mkfifo testfifo alex@danu ~/test/bash $ cat read_from_fifo #!/bin/bash read line echo $line alex@danu ~/test/bash $ ./read_from_fifo < testfifo & [1] 9075 alex@danu ~/test/bash $ echo "Test" > testfifo alex@danu ~/test/bash $ Test [1]+ Done ./read_from_fifo < testfifo
Make sense?DISTRO=Arch
Registered Linux User #388732
- 07-04-2007 #4Just Joined!
- Join Date
- Jun 2007
- Posts
- 5
The fifo worked great. Thanks for your help.


Reply With Quote