Skip to content

Commit 8b5bc56

Browse files
authored
fix: fix invoking of binaries on windows (#190)
1 parent a0a5997 commit 8b5bc56

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/tools.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EOL } from "os";
22
import os from 'os';
3-
import { execFileSync, execSync } from "child_process";
3+
import { execFileSync } from "child_process";
44

55
export const RegexNotToBeLogged = /EXHORT_.*_TOKEN|ex-.*-token/
66
/**
@@ -126,12 +126,14 @@ export function getGitRootDir(cwd) {
126126
* @returns {string}
127127
*/
128128
export function invokeCommand(bin, args, opts={}) {
129-
// .bat and .cmd files can't be executed in windows with execFileSync, so we special case them
130-
// to use execSync here to keep the amount of escaping we need to do to a minimum.
129+
// .bat and .cmd files can't be executed in windows with execFileSync without {shell: true}, so we
130+
// special case them here to keep the amount of escaping we need to do to a minimum.
131131
// https://nodejs.org/docs/latest-v20.x/api/child_process.html#spawning-bat-and-cmd-files-on-windows
132-
if (process.platform === 'win32' && (bin.endsWith(".bat") || bin.endsWith(".cmd"))) {
132+
// https://github.com/nodejs/node/issues/52681#issuecomment-2076426887
133+
if (process.platform === 'win32') {
134+
opts = {...opts, shell: true}
133135
args = args.map(arg => handleSpacesInPath(arg))
134-
return execSync(`${handleSpacesInPath(bin)} ${args.join(" ")}`, {...{stdio: 'pipe', encoding: 'utf-8'}, ...opts})
136+
bin = handleSpacesInPath(bin)
135137
}
136138

137139
return execFileSync(bin, args, {...{stdio: 'pipe', encoding: 'utf-8'}, ...opts})

0 commit comments

Comments
 (0)