使用Java应用程序打开VIM

问题描述 投票:0回答:1

我需要我的Java控制台应用程序来执行以下操作:

  1. 打开VIM
  2. <用户输入多行单词和:wq>
  3. 然后我的应用程序应该能够获取vim输入并将其打印在终端中。

到目前为止,我被困在1 ..似乎不可能让Java打开VIM!

这是我一直在摆弄的一些非功能性代码:

call system text editor

http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java

建议非常感谢

编辑

好的,以下将打开VIM但背景。有什么方法吗?

String[] command = {"/usr/bin/vim", "test.txt"};
Process vimProcess = Runtime.getRuntime().exec(command);
vimProcess.waitFor();
java vim
1个回答
0
投票
  1. 从java运行vim(注意这将在gnome上运行,如果你使用KDE使用“konsole”): Process pr = Runtime.getRuntime().exec("gnome-terminal -e 'vim /tmp/tmpfile'");
  2. 等待用户完成并退出: int exitVal = pr.waitFor(); //check for the right exitVal
  3. 读取输入并写入终端: System.out.println(FileUtils.raedFileToString(new File("/tmp/tmpfile")));
© www.soinside.com 2019 - 2024. All rights reserved.