Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 787
Psl Avatar asked Jun 21 '26 05:06

Psl


1 Answers

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) { 
like image 60
Peter Lyons Avatar answered Jun 22 '26 17:06

Peter Lyons



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!