Use pipe for WSL2 (#194010)

This commit is contained in:
Martin Aeschlimann
2023-09-25 23:36:05 +02:00
committed by GitHub
parent 35a34cd1f3
commit 1b5c0af328

View File

@@ -86,7 +86,6 @@ const cliCommandCwd = process.env['VSCODE_CLIENT_COMMAND_CWD'] as string;
const cliRemoteAuthority = process.env['VSCODE_CLI_AUTHORITY'] as string;
const cliStdInFilePath = process.env['VSCODE_STDIN_FILE_PATH'] as string;
export async function main(desc: ProductDescription, args: string[]): Promise<void> {
if (!cliPipe && !cliCommand) {
console.log('Command is only available in WSL or inside a Visual Studio Code terminal.');
@@ -271,7 +270,16 @@ export async function main(desc: ProductDescription, args: string[]): Promise<vo
if (verbose) {
console.log(`Invoking: cd "${cliCwd}" && ELECTRON_RUN_AS_NODE=1 "${cliCommand}" "${newCommandline.join('" "')}"`);
}
_cp.spawn(cliCommand, newCommandline, { cwd: cliCwd, env, stdio: ['inherit'] });
if (runningInWSL2()) {
if (verbose) {
console.log(`Using pipes for output.`);
}
const cp = _cp.spawn(cliCommand, newCommandline, { cwd: cliCwd, env, stdio: ['inherit', 'pipe', 'pipe'] });
cp.stdout.on('data', data => process.stdout.write(data));
cp.stderr.on('data', data => process.stderr.write(data));
} else {
_cp.spawn(cliCommand, newCommandline, { cwd: cliCwd, env, stdio: 'inherit' });
}
}
} else {
if (parsedArgs.status) {
@@ -331,6 +339,17 @@ export async function main(desc: ProductDescription, args: string[]): Promise<vo
}
}
function runningInWSL2(): boolean {
if (!!process.env['WSL_DISTRO_NAME']) {
try {
return _cp.execSync('uname -r', { encoding: 'utf8' }).includes('-microsoft-');
} catch (_e) {
// Ignore
}
}
return false;
}
async function waitForFileDeleted(path: string) {
while (_fs.existsSync(path)) {
await new Promise(res => setTimeout(res, 1000));