我有一个命令行程序,我将重定向的输入传递给该文件,并通过管道传递给一个文件:
./program < some_input_file > some_output_file
这显然写入了不包括重定向输入的输出。有没有一些简单的方法来获取程序日志,包括我传入的重定向输入?
我愿意使用外部程序或脚本 - 我在 bash/linux 上运行它。
[编辑]
我正在寻找一种让输出交错的方法——就好像程序是在终端中运行的,输入文件只是手动输入
最佳答案
以下是如何执行此操作的示例:
> cat input.txt
asdf
qwer
zxcv
> tee output.txt < input.txt | cat >> output.txt
> cat output.txt
asdf
qwer
zxcv
asdf
qwer
zxcv
只需用您的程序替换上面的 cat
就可以了。现在,如果你想让它交错,那么你必须做一些不同的事情:
> while read line
do
echo $line >> output.txt
echo $line | cat >> output.txt
done < 'input.txt'
> cat output.txt
asdf
asdf
qwer
qwer
zxcv
zxcv
再次用您的 shell 脚本替换 cat
。
关于bash - 包含重定向标准输入的程序的控制台输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5671111/