2

I have a console program which uses standard input and output.

For example I call : ./program_name and after that I enter input

I need to make this two actions in one command like: ./program_name 'my input string' (this command returns Abort trap: 6).

How to do that?

I haven't source code for the program.

11

Use a here string

./program_name <<< 'my input string'

or a here document (longer, but standard):

./program_name <<EOF
my input string
EOF
  • 2
    This is the better answer, since it doesn't start an additional process like the pipeline does. – chepner Sep 28 '15 at 18:26
4
echo my input string | ./program_name

Or, if you are a quotist:

echo "my input string" | ./program_name

Another handy tip is a subshell to collect output from multiple sources, for example:

( echo header; cat /etc/passwd; echo footer ) | ./program_name
  • 2
    I think it would be much more readable if you put my input string in quotes. – Peschke Sep 28 '15 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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