From c5cbde1a3cd51687dd7fa887be8ae075417a0ca4 Mon Sep 17 00:00:00 2001 From: Tobias Hopp Date: Thu, 28 Mar 2024 02:53:16 +0100 Subject: [PATCH] Fix issue when using sudo that spawn sometimes will result in error --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 25e765e..8103ae9 100644 --- a/index.js +++ b/index.js @@ -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) );