Skip to content

Commit 872bd0f

Browse files
committed
app: electron: Replace execSync with execFileSync
1 parent ced9dec commit 872bd0f

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

app/electron/main.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ChildProcessWithoutNullStreams, exec, execSync, spawn } from 'child_process';
17+
import {
18+
ChildProcessWithoutNullStreams,
19+
exec,
20+
execFileSync,
21+
spawn,
22+
spawnSync,
23+
} from 'child_process';
1824
import { randomBytes } from 'crypto';
1925
import dotenv from 'dotenv';
2026
import {
@@ -91,7 +97,9 @@ const args = yargs(hideBin(process.argv))
9197
() => {
9298
try {
9399
const backendPath = path.join(process.resourcesPath, 'headlamp-server');
94-
const stdout = execSync(`${backendPath} list-plugins`);
100+
const stdout = execFileSync(backendPath, ['list-plugins'], {
101+
encoding: 'utf-8',
102+
});
95103
process.stdout.write(stdout);
96104
process.exit(0);
97105
} catch (error) {
@@ -1090,7 +1098,13 @@ async function getRunningHeadlampPIDs() {
10901098
function killProcess(pid: number) {
10911099
if (process.platform === 'win32') {
10921100
// Otherwise on Windows the process will stick around.
1093-
execSync('taskkill /pid ' + pid + ' /T /F');
1101+
const taskKill = spawnSync('taskkill', ['/pid', String(pid), '/T', '/F'], { stdio: 'ignore' });
1102+
if (taskKill.error) {
1103+
throw taskKill.error;
1104+
}
1105+
if (taskKill.status !== 0) {
1106+
throw new Error(`taskkill exited with status ${taskKill.status}`);
1107+
}
10941108
} else {
10951109
process.kill(pid, 'SIGHUP');
10961110
}

0 commit comments

Comments
 (0)