UNPKG

ctrlc-wrapper

Version:

Wrapper enabling to send CTRL+C signal to child process

34 lines (33 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendCtrlC = exports.spawnWithWrapper = void 0; const child_process_1 = require("child_process"); function spawnWithWrapper(command, argsOrOptions, options) { if (typeof argsOrOptions === 'object' && !Array.isArray(argsOrOptions) && argsOrOptions !== null) { return spawnWithWrapper(command, [], argsOrOptions); } const args = (argsOrOptions || []); if (process.platform === 'win32') { args.unshift(command); const arch = { x64: '64', ia32: '32', }; command = require.resolve(`ctrlc-wrapper-windows-${arch[process.arch]}/start.exe`); } const child = (0, child_process_1.spawn)(command, args, options); child.sendCtrlC = () => sendCtrlC(child); return child; } exports.spawnWithWrapper = spawnWithWrapper; function sendCtrlC(child) { if (process.platform === 'win32') { child.stdin.write('^C\n'); } else { child.kill('SIGINT'); } } exports.sendCtrlC = sendCtrlC;