Skip to content

Commit 4979157

Browse files
committedFeb 4, 2023
bugfixes for windows spawn
1 parent 47674db commit 4979157

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed
 

‎package-lock.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎server/actions/execute-command.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { spawn } from 'child_process';
2-
1+
import { spawn } from '../utils/simple-cross-spawn';
32
import { ZERO } from '../utils/utils';
43

54
export const executeCommand = (
@@ -18,7 +17,6 @@ export const executeCommand = (
1817
const spawned = spawn(command, commandArguments, {
1918
cwd,
2019
detached: false,
21-
shell: process.platform === 'win32',
2220
});
2321

2422
// wait for stdout, stderr
@@ -34,9 +32,6 @@ export const executeCommand = (
3432

3533
// wait for finish and resolve
3634
spawned.on('close', (exitStatus: number) => {
37-
if (!process.env['NODE_TEST']) {
38-
// console.log(exitStatus);
39-
}
4035
if (exitStatus === ZERO) {
4136
resolve({
4237
stdout,

‎server/utils/simple-cross-spawn.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { ChildProcess, SpawnOptionsWithoutStdio } from 'child_process';
2+
import { spawn as cpSpawn } from 'child_process';
3+
4+
const metaCharsRegExp = /([ !"%&()*,;<>?[\]^`|])/g;
5+
6+
export const spawn = (
7+
command: string,
8+
arguments_?: readonly string[],
9+
options?: SpawnOptionsWithoutStdio,
10+
): ChildProcess => {
11+
if (process.platform !== 'win32') {
12+
return cpSpawn(command, arguments_, options);
13+
}
14+
15+
const shellCommand = [
16+
command,
17+
...(arguments_ || []).map((argument) =>
18+
`"${argument}"`.replace(metaCharsRegExp, '^$1'),
19+
),
20+
].join(' ');
21+
22+
return cpSpawn(
23+
process.env['comspec'] || 'cmd.exe',
24+
['/d', '/s', '/c', `"${shellCommand}"`],
25+
{
26+
...options,
27+
windowsVerbatimArguments: true,
28+
},
29+
);
30+
};

0 commit comments

Comments
 (0)
Failed to load comments.