How to start a program with bash -c, redirect / disable GUI of that app











up vote
0
down vote

favorite












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()
}









share|improve this question




























    up vote
    0
    down vote

    favorite












    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()
    }









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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()
      }









      share|improve this question















      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()
      }






      bash go






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday

























      asked yesterday









      G-M

      961111




      961111
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          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





          share|improve this answer





















          • Thanks, works like a charm!
            – G-M
            yesterday










          • @G-M Which solution works for you ?
            – mgagnon
            yesterday










          • @mgagnon #2 DISPLAY= bash -c java -jar app.jar -config config.json
            – G-M
            yesterday











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409114%2fhow-to-start-a-program-with-bash-c-redirect-disable-gui-of-that-app%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          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





          share|improve this answer





















          • Thanks, works like a charm!
            – G-M
            yesterday










          • @G-M Which solution works for you ?
            – mgagnon
            yesterday










          • @mgagnon #2 DISPLAY= bash -c java -jar app.jar -config config.json
            – G-M
            yesterday















          up vote
          2
          down vote



          accepted










          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





          share|improve this answer





















          • Thanks, works like a charm!
            – G-M
            yesterday










          • @G-M Which solution works for you ?
            – mgagnon
            yesterday










          • @mgagnon #2 DISPLAY= bash -c java -jar app.jar -config config.json
            – G-M
            yesterday













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          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





          share|improve this answer












          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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          el.pescado

          15.7k22771




          15.7k22771












          • Thanks, works like a charm!
            – G-M
            yesterday










          • @G-M Which solution works for you ?
            – mgagnon
            yesterday










          • @mgagnon #2 DISPLAY= bash -c java -jar app.jar -config config.json
            – G-M
            yesterday


















          • Thanks, works like a charm!
            – G-M
            yesterday










          • @G-M Which solution works for you ?
            – mgagnon
            yesterday










          • @mgagnon #2 DISPLAY= bash -c java -jar app.jar -config config.json
            – G-M
            yesterday
















          Thanks, works like a charm!
          – G-M
          yesterday




          Thanks, works like a charm!
          – G-M
          yesterday












          @G-M Which solution works for you ?
          – mgagnon
          yesterday




          @G-M Which solution works for you ?
          – mgagnon
          yesterday












          @mgagnon #2 DISPLAY= bash -c java -jar app.jar -config config.json
          – G-M
          yesterday




          @mgagnon #2 DISPLAY= bash -c java -jar app.jar -config config.json
          – G-M
          yesterday


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409114%2fhow-to-start-a-program-with-bash-c-redirect-disable-gui-of-that-app%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks