Skip to content

Commit

Permalink
Prevent spawn child to be terminated by parent (#264)
Browse files Browse the repository at this point in the history
Fixes #263
  • Loading branch information
Mikescops authored Jun 11, 2024
1 parent 1df0c61 commit aff922f
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/command-handlers/exec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command } from 'commander';
import { spawn } from 'child_process';
import { spawnSync } from 'child_process';
import { getVaultContent, initVaultContent } from '../modules/database/index.js';
import { logger } from '../logger.js';

Expand All @@ -18,14 +18,13 @@ export const runExec = async (_options: unknown, program: Command) => {
}

// spawn a new process with the command
const child = spawn(command, {
const child = spawnSync(command, {
stdio: 'inherit',
shell: true,
env: environmentVariables,
});

// listen for process exit
child.on('exit', (code) => {
logger.debug(`Child process exited with code ${code ?? 'unknown'}`);
});
if (child.error) {
logger.error(`Failed to execute command: ${child.error.message}`);
}
};

0 comments on commit aff922f

Please sign in to comment.