Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

  2. #2
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    150
    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.

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    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:
    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
    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.

    Make sense?
    DISTRO=Arch
    Registered Linux User #388732

  4. #4
    Just Joined!
    Join Date
    Jun 2007
    Posts
    5
    The fifo worked great. Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...