Search code examples
javancursesprocessbuilderfar

Is it possible to execute terminal-graphical-apps thru java-ProcessBuilder


Is it possible to run subprocesses like Far/MidnightCommander (or other terminal app with ncurses/graphical-interface) from java application with ProcessBuilder or somehow other way?

Standart examples with ProcessBuilder works fine with something simple like ping

new ProcessBuilder().command("ping -n 4 google.com").start(); // :)

, but not worked at all with far

new ProcessBuilder().command("far").start(); // :(

Solution

  • Yes.

    These applications need access to a terminal device to work. If you started the java program from a terminal, you can use that same terminal by letting the new process inherit it:

    new ProcessBuilder().inheritIO().command("top").start(); // :)
    

    Otherwise, you need to start a new terminal emulator to run the program.

    new ProcessBuilder().command("xterm", "top").start(); // :)