mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-17 05:29:44 +02:00
fix(Execute Command Node): Don't spawn console on Windows (#40909)
This commit is contained in:
parent
1d2c879fab
commit
52aed7ac97
|
|
@ -45,7 +45,13 @@ async function execPromise(command: string, abortSignal?: AbortSignal): Promise<
|
|||
// that detached console and their stdout never reaches our pipe. Windows kills
|
||||
// the tree via `taskkill /T`, so detaching is unnecessary there.
|
||||
const detached = process.platform !== 'win32';
|
||||
const child = spawn(command, { cwd: process.cwd(), shell: true, detached });
|
||||
// `windowsHide` stops Windows from opening a visible console window for the command.
|
||||
const child = spawn(command, {
|
||||
cwd: process.cwd(),
|
||||
shell: true,
|
||||
detached,
|
||||
windowsHide: true,
|
||||
});
|
||||
|
||||
child.stdout.setEncoding('utf8');
|
||||
child.stderr.setEncoding('utf8');
|
||||
|
|
@ -79,7 +85,7 @@ async function execPromise(command: string, abortSignal?: AbortSignal): Promise<
|
|||
return;
|
||||
}
|
||||
if (process.platform === 'win32') {
|
||||
spawn('taskkill', ['/pid', child.pid.toString(), '/T', '/F']);
|
||||
spawn('taskkill', ['/pid', child.pid.toString(), '/T', '/F'], { windowsHide: true });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -84,7 +84,13 @@ describe('ExecuteCommand cancellation', () => {
|
|||
await Promise.resolve();
|
||||
|
||||
controller.abort();
|
||||
expect(mockedSpawn).toHaveBeenCalledWith('taskkill', ['/pid', String(CHILD_PID), '/T', '/F']);
|
||||
expect(mockedSpawn).toHaveBeenCalledWith(
|
||||
'taskkill',
|
||||
['/pid', String(CHILD_PID), '/T', '/F'],
|
||||
{
|
||||
windowsHide: true,
|
||||
},
|
||||
);
|
||||
expect(killSpy).not.toHaveBeenCalled();
|
||||
|
||||
await expect(promise).rejects.toBeInstanceOf(ManualExecutionCancelledError);
|
||||
|
|
|
|||
|
|
@ -64,4 +64,21 @@ describe('ExecuteCommand stdout on Windows', () => {
|
|||
Object.defineProperty(process, 'platform', { value: originalPlatform, configurable: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('hides the console window of the spawned command on Windows', async () => {
|
||||
const originalPlatform = process.platform;
|
||||
Object.defineProperty(process, 'platform', { value: 'win32', configurable: true });
|
||||
try {
|
||||
const promise = node.execute.call(createContext());
|
||||
await Promise.resolve();
|
||||
|
||||
child.emit('close', 0);
|
||||
await promise;
|
||||
|
||||
const spawnOptions = mockedSpawn.mock.calls[0][1] as { windowsHide?: boolean };
|
||||
expect(spawnOptions.windowsHide).toBe(true);
|
||||
} finally {
|
||||
Object.defineProperty(process, 'platform', { value: originalPlatform, configurable: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user