import java.io.*;
public class GnomeCommand {
public static void main(String args[]) throws IOException {
try {
Runtime r = Runtime.getRuntime();
String[] cmdArray = {"/usr/bin/gnome-terminal", "-e", "ps ax | grep gnome", " ; exec $SHELL"};
r.exec(cmdArray).waitFor();
} catch (InterruptedException ex){
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
问题是我无法保持命令提示符打开。它立即关闭。我也使用了“exec $ SHELL”命令,但结果是一样的。我想在执行命令后让终端保持打开状态。无法保持gnome-terminal打开
可能会有所帮助:http://stackoverflow.com/questions/4465930/prevent-gnome-terminal-from-exiting-after-execution –
不实际。我见过这个。但我想知道我的代码中有什么问题? – ahadcse