Skip to content

Commit b35a454

Browse files
committed
escape activation script path if spaces
1 parent e394b68 commit b35a454

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

export.bat

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/eim/loadSettings.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
*/
1818

1919
import { EOL } from "os";
20-
import { OutputChannel } from "../logger/outputChannel";
21-
import { execChildProcess } from "../utils";
20+
import { spawn } from "../utils";
2221
import { IdfSetup } from "./types";
2322
import { getEnvVarsFromIdfTools } from "../pythonManager";
2423
import { IdfToolsManager } from "../idfToolsManager";
@@ -53,25 +52,24 @@ export async function getEnvVariablesFromActivationScript(
5352
"-ExecutionPolicy",
5453
"Bypass",
5554
"-NoProfile",
56-
activationScriptPath,
55+
`'${activationScriptPath.replace(/'/g, "''")}'`,
5756
"-e",
5857
]
59-
: [activationScriptPath, "-e"];
58+
: [`"${activationScriptPath}"`, "-e"];
6059
const shellPath =
6160
process.platform === "win32"
6261
? "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
6362
: "/bin/sh";
64-
const envVarsOutput = await execChildProcess(
63+
const envVarsOutput = await spawn(
6564
shellPath,
6665
args,
67-
process.cwd(),
68-
logToChannel ? OutputChannel.init() : undefined,
6966
{
7067
maxBuffer: 500 * 1024,
7168
cwd: process.cwd(),
69+
shell: shellPath
7270
}
7371
);
74-
const envVars = envVarsOutput.split(EOL);
72+
const envVars = envVarsOutput.toString().trim().split(EOL);
7573
let envDict: { [key: string]: string } = {};
7674
for (const envVar of envVars) {
7775
let keyIndex = envVar.indexOf("=");

src/extension.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4087,23 +4087,27 @@ function createIdfTerminal(extensionPath: string) {
40874087
shellArgs = ["-ExecutionPolicy", "Bypass"];
40884088
}
40894089
}
4090+
const shellPath =
4091+
process.platform === "win32"
4092+
? "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
4093+
: vscode.env.shell;
40904094
const espIdfTerminal = vscode.window.createTerminal({
40914095
name: "ESP-IDF Terminal",
40924096
env: modifiedEnv,
40934097
cwd: workspaceRoot.fsPath || modifiedEnv.IDF_PATH || process.cwd(),
40944098
strictEnv: true,
40954099
shellArgs,
4096-
shellPath: vscode.env.shell,
4100+
shellPath: shellPath,
40974101
});
4102+
const currentSetup = await getCurrentIdfSetup(workspaceRoot);
4103+
const activationScriptPathExists = await pathExists(
4104+
currentSetup.activationScript
4105+
);
4106+
const activationScriptPath = activationScriptPathExists
4107+
? currentSetup.activationScript
4108+
: path.join(extensionPath, "export.ps1");
40984109
if (process.platform === "win32") {
4099-
if (vscode.env.shell.indexOf("cmd.exe") !== -1) {
4100-
espIdfTerminal.sendText(path.join(extensionPath, "export.bat"));
4101-
} else if (
4102-
vscode.env.shell.indexOf("powershell") !== -1 ||
4103-
vscode.env.shell.indexOf("pwsh") !== -1
4104-
) {
4105-
espIdfTerminal.sendText(path.join(extensionPath, "export.ps1"));
4106-
}
4110+
espIdfTerminal.sendText(`'${activationScriptPath.replace(/'/g, "''")}'`);
41074111
}
41084112
espIdfTerminal.show();
41094113
});

0 commit comments

Comments
 (0)