3

I have a command line program that I'm passing redirected input to, and piping to a file:

./program < some_input_file > some_output_file

This obviously writes the output not including the redirected input. Is there some simple way to get a log of the program, including the redirected input that I've passed in?

I'm open to using an external program or script - I'm running this on bash/linux.

[EDIT]

I'm looking for a way to get the output interleaved - as if the program was run in a terminal, with the input file just typed in manually

4

2 回答 2

1

以下是如何执行此操作的示例:

> 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

再次替换cat为您的 shell 脚本。

于 2011-04-15T05:23:16.317 回答
1

如果您的程序在读取下一个输入之前打印了某种提示,您可以使用expect它与之交互。您的expect脚本可以在读取每个输入行时打印它,并在看到提示后将其发送到程序。这将为您提供正确的交错输出,而无需每行运行一次程序。

于 2011-04-15T18:22:21.557 回答