标签:
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*"});
标签:
原文地址:http://www.cnblogs.com/rspb/p/4648917.html