Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

linux - Bash: read stdin from file and write stdout to file

I'm trying to run an app (let's say top) so it will read from a file for stdin and write to another file from stdout.

Currently I have

mkfifo stdin.pipe
(tail -f stdin.pipe) | top

which works as expected, as I can then echo something to that file and top will receive it. But I'm unable to redirect the output of top. How can I achieve this?

EDIT:

Ok, let's scratch top. I'm testing with this:

cat test.sh

echo Say something
read something
echo you said $something
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Let's forget about top, that appears to be a red herring.

To map stdin or stdout to files, you can use redirection:

some_program < input_file          # Redirects stdin

another_program > output_file      # Redirects stdout

or even:

yet_another  < input_file > output_file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...