Super User is a question and answer site for computer enthusiasts and power users. 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

is there any way I can pass commands to the CLI of a tool directly?

I would like to script some actions, for example:

./OpenBTS < "tmsis"

I do not need to retrieve the results (I watch it in the log file). Do you have any idea how I could realize that? There is now way to do this using command line parameters, at least not that I found out. So it looks like I have to figure out sth myself. Any idea? Maybe I could automate screen in a way to detect the prompt and "paste" my command there. Are there tools for this on Linux?

share|improve this question

migrated from Jul 31 '11 at 14:25

This question came from our site for professional and enthusiast programmers.

up vote 5 down vote accepted

Sounds like you are looking for expect

share|improve this answer
wow! Exactly! Big thanks. very nice tool, good to knwow it now =) – Steve Jul 31 '11 at 9:37

You can try it with a heredoc, something like:

./OpenBTS <<EOF

as in the following transcript, which feeds input into sed:

pax$ sed 's/^/Q/' <<EOF
> hello
> goodbye

Alternatively, you can just echo stuff directly into it, like

echo "tmsis" | ./OpenBTS

as per the following example:

pax$ echo 'hello
goodbye' | sed 's/^/Q/'
share|improve this answer

There is no specific way to do this, but if the tool listens on stdin then you can use a heredoc for this.

./sometool << EOF
share|improve this answer
Thanks for the idea. It is not working in this case but that's not related to the command. Will use it for sure later. Thx for telling me that trick :) – Steve Jul 31 '11 at 9:37

You must log in to answer this question.