Skip to content

Commit 890360b

Browse files
authored
Rajkumar42/wsl/pipefix (#1170)
Adding sysnative to path if running in windows for remote pipe launch
1 parent abe5430 commit 890360b

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

src/features/processPicker.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as os from 'os';
77
import * as vscode from 'vscode';
88
import * as child_process from 'child_process';
9+
import { PlatformInformation } from '../platform';
910

1011
export interface AttachItem extends vscode.QuickPickItem {
1112
id: string;
@@ -389,33 +390,51 @@ function execChildProcess(process: string, workingDirectory: string): Promise<st
389390
});
390391
}
391392

393+
// VSCode cannot find the path "c:\windows\system32\bash.exe" as bash.exe is only available on 64bit OS.
394+
// It can be invoked from "c:\windows\sysnative\bash.exe", so adding "c:\windows\sysnative" to path if we identify
395+
// VSCode is running in windows and doesn't have it in the path.
396+
function GetSysNativePathIfNeeded() : Promise<any> {
397+
return PlatformInformation.GetCurrent().then(platformInfo => {
398+
let env = process.env;
399+
if (platformInfo.isWindows && platformInfo.architecture === "x86_64") {
400+
let sysnative : String = process.env.WINDIR + "\\sysnative";
401+
env.Path = process.env.PATH + ";" + sysnative;
402+
}
403+
404+
return env;
405+
});
406+
}
407+
392408
function execChildProcessAndOutputErrorToChannel(process: string, workingDirectory: string, channel: vscode.OutputChannel): Promise<string> {
393-
channel.appendLine(`Executing: ${process}`);
409+
channel.appendLine(`Executing: ${process}`);
410+
394411
return new Promise<string>((resolve, reject) => {
395-
child_process.exec(process, { cwd: workingDirectory, maxBuffer: 500 * 1024 }, (error: Error, stdout: string, stderr: string) => {
396-
let channelOutput = "";
397-
398-
if (stdout && stdout.length > 0) {
399-
channelOutput.concat(stdout);
400-
}
412+
return GetSysNativePathIfNeeded().then(newEnv => {
413+
child_process.exec(process, { cwd: workingDirectory, env: newEnv, maxBuffer: 500 * 1024 }, (error: Error, stdout: string, stderr: string) => {
414+
let channelOutput = "";
415+
416+
if (stdout && stdout.length > 0) {
417+
channelOutput.concat(stdout);
418+
}
401419

402-
if (stderr && stderr.length > 0) {
403-
channelOutput.concat(stderr);
404-
}
420+
if (stderr && stderr.length > 0) {
421+
channelOutput.concat(stderr);
422+
}
405423

406-
if (error) {
407-
channelOutput.concat(error.message);
408-
}
424+
if (error) {
425+
channelOutput.concat(error.message);
426+
}
409427

410428

411-
if (error || (stderr && stderr.length > 0)) {
412-
channel.append(channelOutput);
413-
channel.show();
414-
reject(new Error("See remote-attach output"));
415-
return;
416-
}
429+
if (error || (stderr && stderr.length > 0)) {
430+
channel.append(channelOutput);
431+
channel.show();
432+
reject(new Error("See remote-attach output"));
433+
return;
434+
}
417435

418-
resolve(stdout);
436+
resolve(stdout);
437+
});
419438
});
420439
});
421440

0 commit comments

Comments
 (0)