Home > Net >  Using Java ProcessBuilder() to run Noxim Simulator
Using Java ProcessBuilder() to run Noxim Simulator

Time:12-20

Basically, I have a problem which is, I am using ProcessBuilder () to run Noxim simulator from java IDE, but neither the shell opened nor the results returned. It just displayed this error : Exit with error code: 127 I tried the same code to execute the ping command, and it worked and returned the output shown in the shell. I also used the code run Kdeveloper and it worked well. Note: the path is correct as It worked well in the shell

ProcessBuilder processBuilder = new ProcessBuilder();  
processBuilder.command("/home/sa/Bureau/NOXIM/noxim/bin/noxim");
try {

            Process process = processBuilder.start();
            int exitCode = process.waitFor();
            System.out.println("\nExited with error code : "   exitCode);

            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));

            String line;
          while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }

           
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

CodePudding user response:

It's important to read the error stream too. I guess you see some more messages. Have a look here: https://gist.github.com/th-schwarz/041e13ede396a869c7681b5ad637460c

The easiest way is to read the error stream too is: processBuilder.redirectErrorStream(true);

  • Related