diff --git a/src/commands/show.ts b/src/commands/show.ts index ff9b0401..c42df84e 100644 --- a/src/commands/show.ts +++ b/src/commands/show.ts @@ -49,7 +49,7 @@ async function showProblemInternal(channel: vscode.OutputChannel, id: string): P const outdir: string = await selectWorkspaceFolder(); await fse.ensureDir(outdir); - const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "show", id, "-gx", "-l", language, "-o", outdir]); + const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "show", id, "-gx", "-l", language, "-o", `"${outdir}"`]); const reg: RegExp = /\* Source Code:\s*(.*)/; const match: RegExpMatchArray | null = result.match(reg); if (match && match.length >= 2) { diff --git a/src/commands/submit.ts b/src/commands/submit.ts index 044e9b22..cc61ad4d 100644 --- a/src/commands/submit.ts +++ b/src/commands/submit.ts @@ -19,7 +19,7 @@ export async function submitSolution(channel: vscode.OutputChannel, uri?: vscode } try { - const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "submit", filePath]); + const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "submit", `"${filePath}"`]); await showResultFile(result); } catch (error) { await promptForOpenOutputChannel("Failed to submit the solution. Please open the output channel for details.", DialogType.error, channel); diff --git a/src/commands/test.ts b/src/commands/test.ts index f9cb73f0..873fe9f2 100644 --- a/src/commands/test.ts +++ b/src/commands/test.ts @@ -47,7 +47,7 @@ export async function testSolution(channel: vscode.OutputChannel, uri?: vscode.U let result: string | undefined; switch (choice.value) { case ":default": - result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", filePath]); + result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", `"${filePath}"`]); break; case ":direct": const testString: string | undefined = await vscode.window.showInputBox({ @@ -57,7 +57,7 @@ export async function testSolution(channel: vscode.OutputChannel, uri?: vscode.U ignoreFocusOut: true, }); if (testString) { - result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", filePath, "-t", `"${testString.replace(/"/g, "")}"`]); + result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", `"${filePath}"`, "-t", `"${testString.replace(/"/g, "")}"`]); } break; case ":file": @@ -65,7 +65,7 @@ export async function testSolution(channel: vscode.OutputChannel, uri?: vscode.U if (testFile && testFile.length) { const input: string = await fse.readFile(testFile[0].fsPath, "utf-8"); if (input.trim()) { - result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", filePath, "-t", `"${input.replace(/"/g, "").replace(/\r?\n/g, "\\n")}"`]); + result = await executeCommand(channel, "node", [leetCodeBinaryPath, "test", `"${filePath}"`, "-t", `"${input.replace(/"/g, "").replace(/\r?\n/g, "\\n")}"`]); } else { vscode.window.showErrorMessage("The selected test file must not be empty."); } diff --git a/src/leetCodeManager.ts b/src/leetCodeManager.ts index 95f0c426..313fe714 100644 --- a/src/leetCodeManager.ts +++ b/src/leetCodeManager.ts @@ -43,7 +43,7 @@ class LeetCodeManager extends EventEmitter implements ILeetCodeManager { try { const userName: string | undefined = await new Promise(async (resolve: (res: string | undefined) => void, reject: (e: Error) => void): Promise => { let result: string = ""; - const childProc: cp.ChildProcess = cp.spawn("node", [leetCodeBinaryPath, "user", "-l"]); + const childProc: cp.ChildProcess = cp.spawn("node", [leetCodeBinaryPath, "user", "-l"], { shell: true }); childProc.stdout.on("data", (data: string | Buffer) => { data = data.toString(); result = result.concat(data); diff --git a/src/shared.ts b/src/shared.ts index 1862efca..e3eee105 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -3,7 +3,7 @@ import * as path from "path"; import * as vscode from "vscode"; -export const leetCodeBinaryPath: string = path.join(__dirname, "..", "..", "node_modules", "leetcode-cli", "bin", "leetcode"); +export const leetCodeBinaryPath: string = `"${path.join(__dirname, "..", "..", "node_modules", "leetcode-cli", "bin", "leetcode")}"`; export interface IQuickItemEx extends vscode.QuickPickItem { value: T;