好的,这是我的代码:
String[] commands = {"sync && echo 3 > /proc/sys/vm/drop_caches"};
Process pr = Runtime.getRuntime().exec(commands);
pr.waitFor();
我得到:
Exception in thread "main" java.io.IOException: Cannot run program "sync && echo 3 > /proc/sys/vm/drop_caches": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at java.lang.Runtime.exec(Runtime.java:615)
at java.lang.Runtime.exec(Runtime.java:483)
at MyTest.main(MyTest.java:896)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:135)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1021)
我在命令行复制粘贴相同的字符串,我认为工作正常。
问题是什么?我正在使用 Ubuntu 11.10。谢谢