java Runtime.exec() 执行问题
Runtime.exec() 不等同于直接执行command line命令!
Runtime.exec()很有局限性,对有些命令不能直接把command line里的内容当作String参数传给exec().
比如重定向等命令。举个例子:
javap -l xxx > output.txt
这时要用到exec的第二种重载,即input 参数为String[]:
Process p = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","javap -l xxx > output.txt"});
rm -rf name*
Process p = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","rm -rf name*"});
posted on 2015-07-15 17:11 renshaoping 阅读(1252) 评论(0) 收藏 举报
浙公网安备 33010602011771号