MCPcopy Index your code
hub / github.com/microsoft/vscode-cpptools / spawnChildProcessImpl

Function spawnChildProcessImpl

Extension/src/common.ts:799–850  ·  view source on GitHub ↗
(program: string, args: string[], continueOn?: string, skipLogging?: boolean, cancellationToken?: vscode.CancellationToken)

Source from the content-addressed store, hash-verified

797}
798
799async function spawnChildProcessImpl(program: string, args: string[], continueOn?: string, skipLogging?: boolean, cancellationToken?: vscode.CancellationToken): Promise<ProcessOutput> {
800 const result = new ManualPromise<ProcessOutput>();
801
802 let proc: child_process.ChildProcess;
803 if (await isExecutable(program)) {
804 proc = child_process.spawn(`.${isWindows ? '\\' : '/'}${path.basename(program)}`, args, { shell: true, cwd: path.dirname(program) });
805 } else {
806 proc = child_process.spawn(program, args, { shell: true });
807 }
808
809 const cancellationTokenListener: vscode.Disposable | undefined = cancellationToken?.onCancellationRequested(() => {
810 getOutputChannelLogger().appendLine(localize('killing.process', 'Killing process {0}', program));
811 proc.kill();
812 });
813
814 const clean = () => {
815 proc.removeAllListeners();
816 if (cancellationTokenListener) {
817 cancellationTokenListener.dispose();
818 }
819 };
820
821 let stdout: string = '';
822 let stderr: string = '';
823 if (proc.stdout) {
824 proc.stdout.on('data', data => {
825 const str: string = data.toString();
826 if (skipLogging === undefined || !skipLogging) {
827 getOutputChannelLogger().appendAtLevel(1, str);
828 }
829 stdout += str;
830 if (continueOn) {
831 const continueOnReg: string = escapeStringForRegex(continueOn);
832 if (stdout.search(continueOnReg)) {
833 result.resolve({ stdout: stdout.trim(), stderr: stderr.trim() });
834 }
835 }
836 });
837 }
838 if (proc.stderr) {
839 proc.stderr.on('data', data => stderr += data.toString());
840 }
841 proc.on('close', (code, signal) => {
842 clean();
843 result.resolve({ exitCode: code || signal || undefined, stdout: stdout.trim(), stderr: stderr.trim() });
844 });
845 proc.on('error', error => {
846 clean();
847 result.reject(error);
848 });
849 return result;
850}
851
852/**
853 * @param permission fs file access constants: https://nodejs.org/api/fs.html#file-access-constants

Callers 1

spawnChildProcessFunction · 0.85

Calls 12

getOutputChannelLoggerFunction · 0.90
isExecutableFunction · 0.85
escapeStringForRegexFunction · 0.85
appendLineMethod · 0.80
onMethod · 0.80
toStringMethod · 0.80
appendAtLevelMethod · 0.80
trimMethod · 0.80
cleanFunction · 0.70
resolveMethod · 0.65
rejectMethod · 0.65

Tested by

no test coverage detected