击:从文件中读取标准输入和stdout写入文件 [英] Bash: read stdin from file and write stdout to file

查看:109
本文介绍了击:从文件中读取标准输入和stdout写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个应用程序(比方说),所以它会从文件中读取标准输入并写入从标准输出另一个文件。

目前我有

  mkfifo子stdin.pipe
(尾-f stdin.pipe)|最佳

如预期这工作,我可以再回声东西的文件,上面会收到它。
但我无法重定向顶部的输出。
我怎样才能做到这一点?

编辑:

好吧,让我们从头顶部。
我这个测试:

 猫test.sh回声说点什么
读一些
回声你说的东西$


解决方案

让我们忘掉,这似乎是一个红色的鲱鱼。

要映射标准输入或标准输出到文件,可以使用重定向:

  some_program< INPUT_FILE#标准输入重定向another_program> OUTPUT_FILE#标准输出重定向

甚至是:

  yet_another< INPUT_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

解决方案

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

这篇关于击:从文件中读取标准输入和stdout写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆