How can I execute bat file from windows with credentials.
Checked this solution and just curious how to pass the credentials to login to unix server and then do some steps using bat file?
fs.chmodSync('./myFile.bat', 0o755);
let spawn = require('child_process').spawn,
ls = spawn('cmd.exe',["/c", `C:\\myFile.bat`], ["","\\data\\myFromFolder"] );
ls.stdout.on('stdout', function (error, stdout, stderr) {
if (error) {
console.error(error);
return;
}
console.log('stdout: ' stdout);
});
Basically I need to pass parameters to the bat file. from the javascrpt code.
I set some default parameters in the .bat file, But the first three param has to be local folder path, username , password
Similar to this issue
CodePudding user response:
I was able to run bat file passing credentials as params with below code.
let spawn = require('child_process').spawn;
let bat = require.resolve('<Full path to bat file>');
let ls = spawn(bat, ['<Full path to source folder>','username','password']);
ls.stdout.on('data', function (data) {
console.log('stdout: ' data)
});
ls.stderr.on('data', function (data) {
console.log('stderr: ' data);
});
ls.on('exit', function (code) {
console.log('child process exited with code ' code);
});
Supported by Solution