How can I launch VI from within Java under commons-exec?

后端 未结 3 853
孤街浪徒
孤街浪徒 2020-12-20 23:50

I would like to be able to launch VI from within my Java program and wait for the user to quit VI before proceeding. Here\'s the code snippet that I have currently:

3条回答
  •  遥遥无期
    2020-12-21 00:25

    I'm not sure how to do it with commons-exec,

    But standard Java should be something along the lines of...

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

    This will cause the current thread to wait for the process to complete. You can also use vimProcess.getInputStream(), getOutputStream() and getErrorStream() to redirect those to log files or wherever you want it to go.

    See here for more details. http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html

    Hopefully this helps.

提交回复
热议问题