Abhishek Sarolia
Abhishek Sarolia

Reputation: 73

Not able to resolve the directory paths with child_process exec call in Node.js

What i am trying to do:

I am tying to create an search engine with Node.js

What i have done so far:

I created a test program in Java and done the POC whether the search is being performed correctly or not. And its working perfectly with the command prompt. Then i exported the program into executable JAR file and executed that JAR file via the command prompt successfully.

Now i am trying to give web interface to this program via Node.js and trying to call the JAR file from it. So far i have managed all the bits and pieces on views and routers for application. But now when i am trying to call the JAR file using the Node child process facing error as -

stderr: 'C:\Program' is not recognized as an internal or external command, operable program or batch file.

exec error: Error: Command failed: 'C:\Program' is not recognized as an internal or external command, operable program or batch file.

My code which is giving error is as below -

     var exec = require('child_process').exec, child;


     child = exec('C:\\Program Files\\Java\\jre6\\bin java -jar C:\\java\\ease.jar '+ newstr,

     function (error, stdout, stderr){

     console.log('stdout: ' + stdout);

     console.log('stderr: ' + stderr);

     if(error !== null){

             console.log('exec error: ' + error);

      }

      });

I tried to search the API and google too but no avail, as i am not able to figure out how to give correctly the path string.

Upvotes: 2

Views: 2733

Answers (1)

Kevin Reilly
Kevin Reilly

Reputation: 6252

When using exec, the first argument is The command to run, with space-separated arguments. So, it thinks the executable to execute is C:\Program since there is a space after Program. Also, it seems you might be missing a \ after bin and before java or that you don't need to provide the path.

The following might work (unsure and unable to test):

exec('"C:\\Program Files\\Java\\jre6\\bin\\java" -jar C:\\java\\ease.jar '+ newstr);

Upvotes: 4

Related Questions