From e5ddcfed075c2d1bf3eddcb2772fa5c87d92a7ef Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 23 Jun 2016 16:44:16 -0700 Subject: [PATCH 1/2] Allow space in exec cmds --- Gulpfile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gulpfile.ts b/Gulpfile.ts index 2e6081bea4a..08dc48dde9d 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -69,7 +69,7 @@ function exec(cmd: string, args: string[], complete: () => void = (() => {}), er console.log(`${cmd} ${args.join(" ")}`); // TODO (weswig): Update child_process types to add windowsVerbatimArguments to the type definition const subshellFlag = isWin ? "/c" : "-c"; - const command = isWin ? [cmd, ...args] : [`${cmd} ${args.join(" ")}`]; + const command = isWin ? [cmd.indexOf(" ") >= 0 ? `"${cmd}"` : cmd, ...args] : [`${cmd} ${args.join(" ")}`]; const ex = cp.spawn(isWin ? "cmd" : "/bin/sh", [subshellFlag, ...command], { stdio: "inherit", windowsVerbatimArguments: true } as any); ex.on("exit", (code) => code === 0 ? complete() : error(/*e*/ undefined, code)); ex.on("error", error); From 034c41822ea35bc0086780b400349060358c8fc9 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 24 Jun 2016 11:01:16 -0700 Subject: [PATCH 2/2] extract expression into function --- Gulpfile.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Gulpfile.ts b/Gulpfile.ts index 08dc48dde9d..74113b4b0c7 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -69,12 +69,15 @@ function exec(cmd: string, args: string[], complete: () => void = (() => {}), er console.log(`${cmd} ${args.join(" ")}`); // TODO (weswig): Update child_process types to add windowsVerbatimArguments to the type definition const subshellFlag = isWin ? "/c" : "-c"; - const command = isWin ? [cmd.indexOf(" ") >= 0 ? `"${cmd}"` : cmd, ...args] : [`${cmd} ${args.join(" ")}`]; + const command = isWin ? [possiblyQuote(cmd), ...args] : [`${cmd} ${args.join(" ")}`]; const ex = cp.spawn(isWin ? "cmd" : "/bin/sh", [subshellFlag, ...command], { stdio: "inherit", windowsVerbatimArguments: true } as any); ex.on("exit", (code) => code === 0 ? complete() : error(/*e*/ undefined, code)); ex.on("error", error); } +function possiblyQuote(cmd: string) { + return cmd.indexOf(" ") >= 0 ? `"${cmd}"` : cmd; +} let useDebugMode = true; let host = cmdLineOptions["host"];