#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Sheffield, UK
    Posts
    28
    Rep Power
    0

    automatically pipe text to a program


    Hi there, I have a little prgram that executes commands. One of the commands involves a program that has the format as follows:

    #prog
    please enter A: [user text 1]
    please enter B: [user text 2]
    please enter C: [user text 3]
    -- results --
    #

    Can you think of a way to automatically send [user text i] from the command line.

    Thanks
  2. #2
  3. No Profile Picture
    Not there when you need me
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Oct 2001
    Location
    Berlin, Germany
    Posts
    1,430
    Rep Power
    14
  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Sheffield, UK
    Posts
    28
    Rep Power
    0
    What I mean is that my program runs commands as if they were at teh command prompt and there is a program that doesn't use params but requires the user to type them in.

    Basically I'm writing a program that does some automation, a similar example would be writing a script like such:
    setPassword $username$ $password$
    which would then run the unix passwd command
  6. #4
  7. No Profile Picture
    Not there when you need me
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Oct 2001
    Location
    Berlin, Germany
    Posts
    1,430
    Rep Power
    14
    Assuming that the user inputs are separated by the return key, you can simply echo the stuff you get from the user with some newlines into a temporary file and pass that to the program's stdin.

    Like this:
    Code:
    echo "" > /tmp/tmpinput
    chmod 700 /tmp/tmpinput
    
    echo "$1" > /tmp/tmpinput
    echo -e "\n" > /tmp/tmpinput
    # etc.
    
    myprog < /tmp/tmpinput
    
    rm /tmp/tmpinput
    I don't know if it works, though.

    Btw: I hope you took passwd just as an example. You shouldn't try to do it really with that or any other security-related command.
  8. #5
  9. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Sheffield, UK
    Posts
    28
    Rep Power
    0
    Yeah passwd's just an example. It works fine, thanks.

IMN logo majestic logo threadwatch logo seochat tools logo