Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering if I could redirect a file to the stdin of a program so that I could actually see the lines of the file as they're being used.

Suppose I have a CLI program with the following flow (in a loop): A) Computer asks question B) User answers it C) Computer responds

Running this interactively yields output (which can be copied and pasted from the terminal) that intermixes user answers with computer generated text.

I need to get the same result for a situation where the program is run non-interactively and where the answers are predefined in a file.

Running program

Is there a way to get the same kind of text that would appear on the terminal screen of such a program run interactively?

share|improve this question
An equivalent question might be to ask if I can run such a program, detect if it happens to be waiting on input, and feed it a line from my file if it does (while printing the same line to the same output my program writes to). – PSkocik Oct 31 '12 at 22:14

You might want to have a look at expect

share|improve this answer

Your Answer


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.