Linux: Send keyboard input to background process

This is a discussion on Linux: Send keyboard input to background process within the Tech Board forums, part of the Community Boards category; This is a Linux specific doubt. I start a process, that waits for keyboard input. I press Ctrl+z, and the ...

  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
    32,851
    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, 06: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21