Sign up ×
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 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.

share|improve this question

2 Answers 2

up vote 9 down vote accepted

Use a here string

./program_name <<< 'my input string'

or a here document (longer, but standard):

./program_name <<EOF
my input string
EOF
share|improve this answer
2  
This is the better answer, since it doesn't start an additional process like the pipeline does. –  chepner yesterday
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
share|improve this answer
2  
I think it would be much more readable if you put my input string in quotes. –  Elixir of Love yesterday

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.