dongyied24121 2018-11-21 09:40
浏览 64
已采纳

如何使用bash -c启动程序,重定向/禁用该应用程序的GUI

Currently I'm starting a java application with

bash -c java -jar app.jar -config config.json

The app opens a window, displaying some output and closes. The output is also available on stdout, so I don't need (want) the GUI to display.

How can I prevent bash to forward the X output?

Follow up:

I'm running this in a go application, so based on el.pescado's answer, I have implemented this as:

func runcmd(cmd string, workdir string) ([]byte, error) {
  ex := exec.Command("bash", "-c", cmd)
  ex.Env = []string{"DISPLAY= "}
  ex.Dir = workdir
  return ex.Output()
}
  • 写回答

1条回答 默认 最新

  • duanjia4817 2018-11-21 10:07
    关注

    You have several options:

    1. First, you should check if that application can run without GUI (often called "headless" mode)
    2. You can unset DISPLAY variable, so that your app won't find your X11 server - but keep in mind that application might not work without X server

    eg.

    DISPLAY= bash -c java -jar app.jar -config config.json # note space after '='
    # or
    env -u DISPLAY bash -c java -jar app.jar -config config.json
    
    1. You could use in-memory virtual X server such as xfvb and point your application to display its windows there.

    eg.

    Xvfb :1 -screen 0 1600x1200x32
    DISPLAY=:1 bash -c java -jar app.jar -config config.json
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器