mattn / sudo

sudo for windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

An error occurred executing the bat script!

zshuaia opened this issue · comments

commented

If the exit code of the bat script is not 0, the sudo process does not exit

commented

Could you please explain how to reproduce?

commented

I'm sorry for not replying in time.
I executed sudo in nodejs using child_process.
And I executed a bat script using sudo.

var process = require('child_process');
// executed a bat script
var file = process.spawn('sudo.exe', ['xxx.bat']);
file.stdout.on('data', function (data) {    
  console.log('data:',data)
});
file.stdout.on('end', function (data) {   
  console.log('process end',data);
});
file.on('exit', function (code) {   
  console.log('process exit code:', code);
});

If the return value of the bat script is 0, the file on exit event can be triggered.
Otherwise, file on exit will not be executed.
Therefore, the nodejs program cannot know that the sudo process has finished execution and cannot get the return value of the sudo child process.