我有一个模拟简单分布式文件系统的程序。我需要能够在终端窗口中使用emacs在本地打开文件进行读取或写入。我在String []上使用Runtime.exec()来表示命令。如果我使用“emacs”,我可以获得我正在使用的机器来打开emacs窗口(这对运行客户端的任何其他机器都没有帮助)。但是,我无法解决如何使用此过程在终端内打开emacs。我已经尝试添加参数“-nw”,但它似乎没有响应。这就是我目前正在尝试使用的内容:
boolean bool = execute("emacs", "-nw", cachedFile);
private boolean execute(String com, String id, String fileName) {
String[] commands = new String[3];
commands[0] = com;
commands[1] = id;
commands[2] = fileName;
try {
Process p = Runtime.getRuntime().exec(commands);
int blah = p.waitFor();
} catch(Exception e) {
e.printStackTrace();
return false;
}
return true;
}
如果我删除“-nw”,那么我只能获得我在本地工作的机器,为GUI emacs打开一个单独的窗口。这没有用,因为我需要其他远程机器(我通过终端连接)才能查看或编辑文件而X不起作用,因为我不在那些机器上看到新窗口。
我确定“emacs -nw filename”是正确的命令,因为如果我手动将其输入终端,那么它将打开emacs。但是,我希望Runtime.exec()管理此请求。