Open VIM with Java application

*爱你&永不变心* 提交于 2020-01-06 07:17:14

问题


I need my Java console application to do the following:

  1. Open VIM
  2. < the user input multiple lines of words and :wq >
  3. My application should then be able to get the vim input and print it in the terminal.

So far I'm stuck at 1.. It seems impossible to get Java to open VIM!

Here is some non functional code I have been fiddling with:

call system text editor

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

Advice much appreciated

EDIT

Ok so the following will open VIM but backgrounded. Any way around this?

String[] command = {"/usr/bin/vim", "test.txt"};
Process vimProcess = Runtime.getRuntime().exec(command);
vimProcess.waitFor();

回答1:


  1. run vim from java (notice that this will work on gnome, if you use KDE use "konsole"):

    Process pr = Runtime.getRuntime().exec("gnome-terminal -e 'vim /tmp/tmpfile'");

  2. wait the user will finish and exit:

    int exitVal = pr.waitFor(); //check for the right exitVal

  3. read the input and write to the terminal:

    System.out.println(FileUtils.raedFileToString(new File("/tmp/tmpfile")));



来源:https://stackoverflow.com/questions/11559265/open-vim-with-java-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!