【发布时间】:2012-09-04 20:17:21
【问题描述】:
我有test.sh,它调用了一些程序并且该程序输出了一些行。
我的需要是只捕获最后一行输出
所以如果我做简单的事情
bash test.sh | tail -n 1 ========> Command 1
然后我得到错误"Do you want output to go to | or to tail"
所以要解决上述问题,我愿意
(bash test.sh) | tail -n 1 =======> Command 2
然后我得到简单的 1 行日志。到目前为止一切顺利。
现在我需要通过java程序调用上面的命令,所以我将'('作为第一个参数传递给ProcessBuilder,但它抱怨它无法理解'('作为第一个参数。
如何将Command 2 传递给ProcessBuilder 以获取日志的最后一行。
我对 bash 和 linux 不是很熟悉,所以请原谅我的无知。我什至不知道为什么我收到command 1 的错误。
【问题讨论】:
标签: java linux bash shell processbuilder