Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

3 Answers

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
add comment

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
add comment

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
1  
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
add comment

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.