node.js - How to excute .bat script on windows from node js -


i have node js file excute bat file. tried using exec of node js child-process module no luck

let me share node js script:

var starttime = '2014-11-27 17:0:42'; var threadname = '<thread 0>'; var categoryname ='alarmcategory'; var alarmlevel = 'fatal'; var alarmcategory = 'os'; var alarmmessage = 'corrupt';  var cp = require('child_process'); msg = cp.exec('handler.bat' +" " + starttime ,function (error, stdout, stderr) {     if (error) {         console.log(error.stack);         console.log('error code: '+error.code);         console.log('signal received: '+error.signal);     }     console.log('child process stdout: '+stdout);     console.log('child process stderr: '+stderr); }); 

my bat script . script takes input parms , echos.

 @echo off set starttime=%1 set thread=%2 set categoryname=%3 set alarmlevel=%4 set alarmcategory=%5 set alarmmessage=%6 echo ##################### echo tool users info echo ##################### echo hi %arg1% 

for printing 1 arg.

error getting :

"c:\program files (x86)\jetbrains\webstorm 8.0.4\bin\runnerw.exe" "c:\program files\nodejs\node.exe" test\test_cmd.js error: command failed: 'handler.bat' not recognized internal or external command, operable program or batch file. 

i resolved issue. using execfile() function since need pass arguments. important note when use execute command using execfile() make sure set "cwd" option in command of exefile(). since looks child process file , not find file. setting full path directly .bat file not work .

i did ,

msg = cp.execfile('handler.bat' ,[starttime,threadname] ,{cwd:'/node js/baflog/sigma-logger/test'},function (error, stdout, stderr) { .... .. ... } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -