Redirect file output to standard output

I have a program that can only output its results to files with the option -o. This time I need to output it to the console, i.e. stdout. Here is my first attempt:

myprog -o /dev/stdout input_file

But he says:

/ dev / not writeable

I found this question that is similar to mine, but /dev/stdoutobviously will not work without any additional magic.

Q: How to redirect the output from a file to stdout?

PS Conventional methods without any specialized software are preferred.

+4
source share
3 answers

- stdin/stdout . .

:

myprog -o - input_file
+5

, :

pipename=/tmp/mypipe.$$
mkfifo "$pipename"

./myprog -o "$pipename" &

while read line
do
    echo "output from myprog: $line"
done < "$pipename"

rm "$pipename"

, /tmp, . $$ PID .

, . , " ", , ( ).

script, .

, .

+4

cat , myprog.

myprog -o tmpfile input_file && cat tmpfile

- myprog - , .

, myprog (, notmyprog) , .

, - ,

myprog -o tmpfile input_file && contents=`cat tmpfile` && rm tmpfile && echo "$contents"

Saves the contents of the file in a variable so that it can be accessed after deleting the file. Note the quotes in the command argument echo. They are important for saving newlines in the file contents.

+2
source

All Articles