可以通过Java的ProcessBuilder执行终端图形应用程序吗?

huangapple go评论67阅读模式
英文:

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

问题

这是可能从Java应用程序中使用ProcessBuilder或其他方式运行类似Far/MidnightCommander(或其他带有ncurses/图形界面的终端应用程序)的子进程吗?

使用ProcessBuilder的标准示例对于像ping这样的简单命令可以正常工作:

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

但是对于far却一点用都没有:

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

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(); // :(

答案1

得分: 1

是的。

这些应用程序需要访问终端设备才能运行。如果您是从终端启动了Java程序,您可以让新进程继承它:

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

否则,您需要启动一个新的终端模拟器来运行该程序:

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

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(); // :)

huangapple
  • 本文由 发表于 2020年8月10日 19:21:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63339194.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定