MCPcopy Index your code
hub / github.com/LeetCode-OpenSource/vscode-leetcode / executeCommand

Function executeCommand

src/utils/cpUtils.ts:12–40  ·  view source on GitHub ↗
(command: string, args: string[], options: cp.SpawnOptions = { shell: true })

Source from the content-addressed store, hash-verified

10}
11
12export async function executeCommand(command: string, args: string[], options: cp.SpawnOptions = { shell: true }): Promise<string> {
13 return new Promise((resolve: (res: string) => void, reject: (e: Error) => void): void => {
14 let result: string = "";
15
16 const childProc: cp.ChildProcess = cp.spawn(command, args, { ...options, env: createEnvOption() });
17
18 childProc.stdout?.on("data", (data: string | Buffer) => {
19 data = data.toString();
20 result = result.concat(data);
21 leetCodeChannel.append(data);
22 });
23
24 childProc.stderr?.on("data", (data: string | Buffer) => leetCodeChannel.append(data.toString()));
25
26 childProc.on("error", reject);
27
28 childProc.on("close", (code: number) => {
29 if (code !== 0 || result.indexOf("ERROR") > -1) {
30 const error: IExecError = new Error(`Command "${command} ${args.toString()}" failed with exit code "${code}".`);
31 if (result) {
32 error.result = result; // leetcode-cli may print useful content by exit with error code
33 }
34 reject(error);
35 } else {
36 resolve(result);
37 }
38 });
39 });
40}
41
42export async function executeCommandWithProgress(message: string, command: string, args: string[], options: cp.SpawnOptions = { shell: true }): Promise<string> {
43 let result: string = "";

Callers 4

executeCommandExMethod · 0.90
toWslPathFunction · 0.90
toWinPathFunction · 0.90

Calls 2

createEnvOptionFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected