Skip to content

Commit 681dfe2

Browse files
authored
Merge pull request #124 from NativeScript/pete/fix-use-cmd-win
Always use cmd when executing node child processes on Windows
2 parents 1948316 + 4ff4a19 commit 681dfe2

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Diff for: src/project/nativeScriptCli.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {spawn, execSync, ChildProcess} from 'child_process';
22
import {Version} from '../common/version';
33
import {Logger, Tags} from '../common/logger';
44
import * as utils from '../common/utilities';
5+
import * as os from 'os';
56

67
export enum CliVersionState {
78
NotExisting,
@@ -44,13 +45,22 @@ export class CliVersion {
4445

4546
export class NativeScriptCli {
4647
private _path: string;
48+
private _shellPath: string;
4749
private _cliVersion: CliVersion;
4850
private _logger: Logger;
4951

5052
constructor(cliPath: string, logger: Logger) {
5153
this._path = cliPath;
5254
this._logger = logger;
5355

56+
this._shellPath = process.env.SHELL;
57+
58+
// always default to cmd on Windows
59+
// workaround for issue #121 https://github.com/NativeScript/nativescript-vscode-extension/issues/121
60+
if (os.platform().indexOf("win") != -1) {
61+
this._shellPath = "cmd.exe";
62+
}
63+
5464
let versionStr = null;
5565
try {
5666
versionStr = this.executeSync(["--version"], undefined);
@@ -73,16 +83,17 @@ export class NativeScriptCli {
7383
}
7484

7585
public executeSync(args: string[], cwd: string): string {
76-
let command: string = `${this._path} ` + args.join(' ');
86+
let command: string = `${this._path} ${args.join(' ')}`;
7787
this._logger.log(`[NativeScriptCli] execute: ${command}`, Tags.FrontendMessage);
78-
return execSync(command, { encoding: "utf8", cwd: cwd, shell: process.env.SHELL }).toString().trim();
88+
89+
return execSync(command, { encoding: "utf8", cwd: cwd, shell: this._shellPath}).toString().trim();
7990
}
8091

8192
public execute(args: string[], cwd: string): ChildProcess {
82-
let command: string = `${this._path} ` + args.join(' ');
93+
let command: string = `${this._path} ${args.join(' ')}`;
8394
this._logger.log(`[NativeScriptCli] execute: ${command}`, Tags.FrontendMessage);
8495

85-
let options = { cwd: cwd, shell: process.env.SHELL };
96+
let options = { cwd: cwd, shell: this._shellPath };
8697
let child: ChildProcess = spawn(this._path, args, options);
8798
child.stdout.setEncoding('utf8');
8899
child.stderr.setEncoding('utf8');

0 commit comments

Comments
 (0)