Server Fault is a question and answer site for system and network administrators. 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 have a program that normally takes a file name as input for a file to read from but instead, for scripting purposes , I want to pass the file contents as a parameter. I cannot re write the program to read the text from command line. Is there a way to pass the contents as text via command line? The file is a binary file.

Ex: prog file.txt -p 0

share|improve this question
Just for future reference, there is a unix specific stack exchange site that is great for asking shell and scripting type questions. – Caleb Apr 21 '11 at 9:09
up vote 2 down vote accepted

If you use bash you can use the so called process substitution feature (<()), e.g.:

prog <(echo $SOME_DATA) -p 0
share|improve this answer

Here's another way to do it on linux:

$ cat $SOME_DATA | prog /dev/stdin -p 0

in this case you're squirting the data into STDIN for prog, and then reading from STDIN via the special device /dev/stdin. Note that /dev/fd/1 is equivalent.

share|improve this answer

I'm not sure these other answers are correct or will work.

Standard is to use - to represent STDIN. When you program parses your ARGV arguments and tries to open the file, then it will map to the STDIN file handle.

cat $SOME_DATA | prog -p 0 -
share|improve this answer
The - is not something standard, just a convention for programs able to read from STDIN to not read from file but from STDIN instead. So, using - totally depends on whether prog understand what - means. – pepoluan Apr 21 '11 at 9:43

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.