1
votes

I want to invoke NODE JS from JAVA as below:

ProcessBuilder pb = new ProcessBuilder("swagger-to-raml-object","twitter-api-api-docsjson");

I am getting the following error:

CreateProcess error=2, The system cannot find the file specified

My path is properly set for Node js.

What is causing the issue?

1
What about the swagger-to-raml-object and any other file referenced by the program?Grasshopper
No other program referencing this.user3345282
You say you want to invoke nodejs but you're invoking swagger-to-raml-object. Is it invoking node internally? What kind of file is it?Grasshopper

1 Answers

1
votes

A possible solution for this (taken from here) is execute the command /bin/bash and your executable as the argument. This worked for me when I was trying to run a shell script... if you are able to run from command line ./my_super_exec you can run the same from Java:

  /* Tell Java what shell is needed to execute your command */
  private static final String BIN_BASH = "/bin/bash";

  // ...

    int exitValue = 0;
    try {
      ProcessBuilder pb = new ProcessBuilder(BIN_BASH, sh);
      Process p = pb.start();
      exitValue = p.waitFor();
    } catch (IOException | InterruptedException e) {
      return false;
    }
    return exitValue == 0;