Thread: Linux: Send keyboard input to background process

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    722

    Linux: Send keyboard input to background process

    This is a Linux specific doubt.
    I start a process, that waits for keyboard input. I press Ctrl+z, and the process halts. Then I write 'bg' in the console and the process keeps running, in the background.
    Now I want to send keyboard input to the process but I don't know how. Do I need somehow to give focus to the process, and then the input? Or is there any command line to do so?
    Thank you.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well you use 'fg' to bring the process to the fore, then you can provide input in the regular manner

    Example - typing "hello" "world" into cat (just echos back to you) with a pause in between
    Code:
    $ cat
    hello
    hello
    
    [2]+  Stopped                 cat
    $ bg
    [2]+ cat &
    
    [2]+  Stopped                 cat
    $ jobs
    [1]-  Running                 kate &
    [2]+  Stopped                 cat
    $ fg 2
    cat
    world
    world

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    AH! Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. Keyboard input in a Dialog
    By ksarkar in forum C++ Programming
    Replies: 1
    Last Post: 05-20-2005, 05:39 AM
  3. Simple keyboard input
    By Da-Nuka in forum C++ Programming
    Replies: 1
    Last Post: 02-12-2005, 11:33 AM
  4. Need help with keyboard input
    By wiramu in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2003, 02:44 PM
  5. getting input from keyboard, passing to execvp
    By jumpyg in forum C++ Programming
    Replies: 4
    Last Post: 11-02-2003, 08:49 PM