Psl
Psl

Reputation: 3920

spawn a child process in node.js

In node.js am trying to spawn a child process

i have to pass an argument(mode=All) also while executing an exe file

Am doing in the following way.But does not get anything

`var exec = require('child_process').execFile;
var fun =function(){ 
   exec('Sample.exe mode=All', function(err, data) {  
        console.log(err)       
        console.log(data.toString());                       
    });  
}
fun();`

in command line Am getting output as

 `c:\files\Sample.exe mode=All`

output as follows

{"ID":"VM-WIN7-64","OS":"Windows 7"}{"ID":"VM-WIN7-32","OS":"Windows 7"}{"ID":"V M-WIN7-32-1","OS":"Windows 7"}{"ID":"VM-WIN7-32-2","OS":"Windows 8"}

how can i get the above output using node.js

Upvotes: 3

Views: 2573

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 145994

Here's the execFile function signature from the documentation:

child_process.execFile(file, args, options, callback)

You are combining the executable file path with a space and then an argument. The execFile doesn't expect that. Try it according to the docs:

exec('Sample.exe', ['mode=ALL'], {}, function(err, data) { 

Upvotes: 5

Related Questions