Fix issue when using sudo that spawn sometimes will result in error

This commit is contained in:
Tobias Hopp 2024-03-28 02:53:16 +01:00
parent e69c735d64
commit c5cbde1a3c

View File

@ -73,8 +73,10 @@ function initTools(callback) {
*/
function scanNetworks(callback, useSudo) {
const cmd = scanner.cmdLine.split(" ");
const args = cmd.slice(1);
const child = spawn((useSudo ? "sudo " : "" ) + cmd[0], args, { stdio: ['ignore', 'pipe', 'pipe'], detached: true });
let args = cmd.slice(1);
if(useSudo)
args.unshift(cmd[0]);
const child = spawn(useSudo ? "sudo" : cmd[0], args, { stdio: ['ignore', 'pipe', 'pipe'], detached: true });
child.on("error", (err) => callback(err, null) );