Skip to content

Commit

Permalink
Merge pull request #124 from NativeScript/pete/fix-use-cmd-win
Browse files Browse the repository at this point in the history
Always use cmd when executing node child processes on Windows
  • Loading branch information
ivanbuhov authored Mar 31, 2017
2 parents 1948316 + 4ff4a19 commit 681dfe2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/project/nativeScriptCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {spawn, execSync, ChildProcess} from 'child_process';
import {Version} from '../common/version';
import {Logger, Tags} from '../common/logger';
import * as utils from '../common/utilities';
import * as os from 'os';

export enum CliVersionState {
NotExisting,
Expand Down Expand Up @@ -44,13 +45,22 @@ export class CliVersion {

export class NativeScriptCli {
private _path: string;
private _shellPath: string;
private _cliVersion: CliVersion;
private _logger: Logger;

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

this._shellPath = process.env.SHELL;

// always default to cmd on Windows
// workaround for issue #121 https://github.com/NativeScript/nativescript-vscode-extension/issues/121
if (os.platform().indexOf("win") != -1) {
this._shellPath = "cmd.exe";
}

let versionStr = null;
try {
versionStr = this.executeSync(["--version"], undefined);
Expand All @@ -73,16 +83,17 @@ export class NativeScriptCli {
}

public executeSync(args: string[], cwd: string): string {
let command: string = `${this._path} ` + args.join(' ');
let command: string = `${this._path} ${args.join(' ')}`;
this._logger.log(`[NativeScriptCli] execute: ${command}`, Tags.FrontendMessage);
return execSync(command, { encoding: "utf8", cwd: cwd, shell: process.env.SHELL }).toString().trim();

return execSync(command, { encoding: "utf8", cwd: cwd, shell: this._shellPath}).toString().trim();
}

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

let options = { cwd: cwd, shell: process.env.SHELL };
let options = { cwd: cwd, shell: this._shellPath };
let child: ChildProcess = spawn(this._path, args, options);
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
Expand Down

0 comments on commit 681dfe2

Please sign in to comment.