Skip to content

terminal – Process exit code returing as 1

  • by
Spread the love


  Runtime runtime = Runtime.getRuntime();
  String output= "";
  String[] myCommand = null;
  
  if(command.equals("open")) {
      String[] openTerminal = new String[] {
             //"/bin/bash", "-c", 
             "osascript -e 'tell application "Terminal" to do script "" +
                    "echo Welcome to Tectonic" +""'"                   
        };

      myCommand = openTerminal;
  }
  else if(command.equals("close")) {
      String[] closeTerminal = new String[] {
                 "/bin/bash", "-c", 
               "osascript -e 'tell application "Terminal" to close first window' & exit"

            };
      myCommand = closeTerminal;

  }
  else if(command.equals("kill")) {
      String[] killAllTerminal = new String[] {
                 "/bin/bash", "-c", 
                 "osascript -e 'tell application "Terminal" to do script "" +
                        "killall Terminal" +""'"                   

            };
      myCommand = killAllTerminal;
  }



  try
  {
      Process p = runtime.exec(myCommand);
        InputStream stdIn = p.getInputStream();
        InputStreamReader isr = new InputStreamReader(stdIn);
        BufferedReader br = new BufferedReader(isr);

        String line = null;

        
        int exitVal = p.waitFor();

exitVal returning as 1 instead of 0
somehow my machine it returns 0
when i tried with my colleague machines returning 1

i dont remember if i did any configurations in the start
where am i doing wrong

i checked in my terminal i dont see any specific configurations i did can anyone help me here

Leave a Reply

Your email address will not be published. Required fields are marked *