Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have an interactive application that takes input from the keyboard.

Whenever I run the application I always write the same things in the beginning. So I was thinking I could make a file with those things and redirect them to the application with:

myapplication < myinput.txt

The problem is that when I am done with that I want to give control back to the keyboard so I can type the rest of the input. Is it possible? I don't mind using a bash script.

share|improve this question
    
Your app must handle that. After program start, when it hits EOF on fd 0, it should close it and open /dev/tty for reading. Then you can start consuming lines from the keyboard. –  ott-- Dec 26 '12 at 16:24
add comment

1 Answer

up vote 3 down vote accepted

I'm not sure about that one, but if the command you want to use is a simple non-interactive one, and you just want to types things into it (and prepend those with the content of 'myinput.txt', try:

cat myinput.txt - | command

ex:

cat myinput.txt - | grep something

But if you need more complicated interaction, you should probably use expect (which is not trivial to use at first, but very powerful).

share|improve this answer
    
Thanks. However I want firstly the myinput.txt to be sent to the command and after that be able and type things. –  Pithikos Dec 26 '12 at 16:06
    
The command I show above will : first output content of "myinput.txt" and then output content of "-" (which, here, for cat, means the standard input, ie what you'll type next). Try if it works, but as I said, it's limited and not very friendly (especially if the command you type into is something like a visual editor, etc). ex: cat myinput.txt - | ssh user@host works more or less. Finish by typing "exit" and return, and it should exit the ssh... (put : ls -al followed by a return, in myinput.txt, for example) –  Olivier Dulac Dec 26 '12 at 16:23
    
You're right. It actually works. Thanks a dozen :) –  Pithikos Dec 26 '12 at 16:42
    
Enjoy :) (and note that the '-' notation is used in many unix utilities, for example tar, grep, etc., and is usefull for many things) –  Olivier Dulac Dec 27 '12 at 11:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.