问题
I need my Java console application to do the following:
- Open VIM
- < the user input multiple lines of words and :wq >
- 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:
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'");wait the user will finish and exit:
int exitVal = pr.waitFor(); //check for the right exitValread 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