【发布时间】:2011-06-20 13:24:41
【问题描述】:
我创建了一个独立的 java 应用程序,我试图在 Ubuntu 10.04 终端中使用“cd”命令更改目录。我使用了以下代码。
String[] command = new String[]{"cd",path};
Process child = Runtime.getRuntime().exec(command, null);
但是上面的代码给出了以下错误
Exception in thread "main" java.io.IOException: Cannot run program "cd": java.io.IOException: error=2, No such file or directory
谁能告诉我如何实现它?
【问题讨论】:
-
逃避是启动一个新的 shell 并触发你所有的命令 - webmasterworld.com/linux/3613813.htm
标签: java terminal runtime runtime.exec cd