Execute an exe file using node.js
you can try execFile function of child process modules in node.js
Refer:
http://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback
You code should look something like:
var exec = require('child_process').execFile;
var fun =function(){
console.log("fun() start");
exec('HelloJithin.exe', function(err, data) {
console.log(err)
console.log(data.toString());
});
}
fun();
How to call .exe file with arguments from node.js
You need to separate file name and arguments.
Syntax: child_process.execFile(file[, args][, options][, callback])
Node Doc
var exec = require('child_process').execFile;
var opt = function(){
exec('file.EXE', ["arg1", "arg2", "arg3"], function(err, data) {
console.log(err)
console.log(data.toString());
});
}
opt();
In the following example, I'm compiling Main.java using javac.exe.here file name is javac.exe path and Main.java is argument.
Executing an exe with parameters in nodejs
The signature of execFile()
is shown in the Node docs as:
file[, args][, options][, callback]
As you are not providing any options, you should be passing a single array, as in your first example.
execFile('oplrun', ['-de', 'output.dat', 'Test.mod','Test.dat'], function(err, data) {
if(err) {
console.log(err)
}
else
console.log(data.toString());
});
How to exec .exe file from Node.js
I think you should give this a try
child_process.execFile(file[, args][, options][, callback])
file <String> The name or path of the executable file to run
args <Array> List of string arguments
options <Object>
cwd <String> Current working directory of the child process
env <Object> Environment key-value pairs
encoding <String> (Default: 'utf8')
timeout <Number> (Default: 0)
maxBuffer <Number> largest amount of data (in bytes) allowed on stdout or stderr - if exceeded child process is killed (Default: 200\*1024)
killSignal <String> (Default: 'SIGTERM')
uid <Number> Sets the user identity of the process. (See setuid(2).)
gid <Number> Sets the group identity of the process. (See setgid(2).)
callback <Function> called with the output when process terminates
error <Error>
stdout <String> | <Buffer>
stderr <String> | <Buffer>
Related Topics
What's "This" in JavaScript Onclick
Angularjs "Controller As" or "$Scope"
Saving a Text File on Server Using JavaScript
Alternative or Polyfill for Array.From on the Internet Explorer
Throttle Amount of Promises Open at a Given Time
JavaScript Timestamp to Relative Time
How to Get Ssl Certificate Details Using JavaScript
Differencebetween JavaScript and Ecmascript
JavaScript Toisostring() Ignores Timezone Offset
Passing Data to a Jquery UI Dialog
Cross-Browser Bookmark/Add to Favorites JavaScript
How Are JavaScript Arrays Represented in Physical Memory
Why Is There a 'Null' Value in JavaScript
Logical Operator || in JavaScript, 0 Stands for Boolean False