如果我使用外壳:
ps -eaf | grep groovy
我可以得到这样的输出:
[root@test www]# ps -eaf | grep groovy
root 924 539 1 03:15 pts/0 00:00:05 /usr/java/jdk1.6.0_31/bin/java -classpath
/root/dev/groovy-1.8.8/lib/groovy-1.8.8.jar -Dscript.name=./groovysh -Dprogram.name=groovysh
-Dgroovy.starter.conf=/root/dev/groovy-1.8.8/conf/groovy-starter.conf
-Dgroovy.home=/root/dev/groovy-1.8.8 -Dtools.jar=/usr/java/jdk1.6.0_31/lib/tools.jar
org.codehaus.groovy.tools.GroovyStarter --main org.codehaus.groovy.tools.shell.Main
--conf /root/dev/groovy-1.8.8/conf/groovy-starter.conf --classpath .
root 1127 562 0 03:20 pts/1 00:00:00 grep groovy
[root@test www]#
但是如果我在 groovy 中运行这个命令:
proc = "ps -eaf | grep groovy".execute()
proc.waitFor() // => return 1
proc.in.text // => return ""
proc.err.text // => see following
将proc.err.text
是ps
命令文件:
ERROR: Garbage option.
********* simple selection ********* ********* selection by list *********
-A all processes -C by command name
-N negate selection -G by real group ID (supports names)
-a all w/ tty except session leaders -U by real user ID (supports names)
-d all except session leaders -g by session OR by effective group name
-e all processes -p by process ID
T all processes on this terminal -s processes in the sessions given
但如果我运行ps -eaf
它会是正确的。
好像|
不能用,是真的吗?如何解决?