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

后端 未结 3 843
孤街浪徒
孤街浪徒 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:46

    However since Java 1.7 you can use the next example to transparently redirect and have full console functionality

    System.out.println("STARTING VI");
     ProcessBuilder processBuilder = new ProcessBuilder("/usr/bin/vi");
     processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
     processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
     processBuilder.redirectInput(ProcessBuilder.Redirect.INHERIT);
    
     Process p = processBuilder.start();
      // wait for termination.
      p.waitFor();
    System.out.println("Exiting VI");
    

    This will allow you to open VI transparently for JVM 1.7+.

提交回复
热议问题