-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
child_process - windowsHide not working with detached: true #21825
Comments
Possibly related: #15217 (comment) |
It looks like it is because const log = require('fs').openSync('./log.out', 'w');
const c = require('child_process').spawn(
'node.exe',
['C:\\...\\node_modules\\npm\\bin\\npm-cli.js', '-g', 'ls', '--depth', '0'],
{stdio: ['ignore', log, log], detached: true, shell: false, windowsHide: true}
); acts as expected, no window is spawned. |
Hello, I have the same problem. Could you please help me? Example: ==procDumpSpawn.js file Corneliu, |
same thing here on node v10.14.2 |
/cc @nodejs/platform-windows @bzoz is this expected behavior? |
Seems to be the expected behavior per @bzoz's comment. |
per bzoz's comment, the original issue seems to be due to spawning a script, but if spawning an exe it shall be okay, but for my case i was indeed spawning an exe as well. |
@ledmirage use |
@bzoz tried that as well, but the pop up is still there this is the code snippet: |
@ledmirage: what is your exact Node version and what exactly are you trying to run? |
@bzoz i tried node 10.15 for windows |
Looks like this Anyway, all this should be documented and added to |
@bzoz tried both inherit and pipe and together with windowsHide = true, still no luck |
@ledmirage sorry to hear that. It worked for me though, maybe there is something in your app that affects this? Could you verify that a simple script with only the spawn command still exibits this behavior? |
similar problem here, but with shell:true detached:true windowHide: true |
Here is a small example highlighting this issue. The example uses a Node script to spawn a Python script that loops for x seconds, writing the value of the counter to both the console and a file. ------------------counter.py--------------------------- import time
import os
import sys
limit = sys.argv[1] if len(sys.argv) >= 2 else 3
delay = 1
for i in range(1, int(sys.argv[1]) + 1):
print(i)
with open('tmp.txt', 'a') as f:
f.write('{} '.format(i))
f.flush()
os.fsync(f.fileno())
time.sleep(delay) And here is the Node script that runs it const spawn = require('child_process').spawn;
const spawnOptions = {
cwd: __dirname,
stdio: 'ignore',
detached: true,
shell: true,
windowsHide: true
};
const cmd = 'python counter.py 5';
const args = [];
const child = spawn(cmd, [], spawnOptions);
child.unref();
console.log(`Child with pid ${child.pid} spawned`); Case 1: Case 2: Case 3: Case 4: Case 5: Case 6: Case 3 produced the results that I expected for case 1.Namely, that if I wanted to spawn a detached child process that would persist after Node exited, and would run in the background, I would use:
Which is the exact opposite of what the documentation says There are a couple of other permutations that I didn't try, but for those that I did, almost none worked as expected. The most interesting were cases 2 and 3. Based on the documentation and my understanding of Windows, changing the Environment: |
Similar problem here on Windows using Example:
|
Any workaround? |
This annoyed me, so I tracked this down: I was somewhat suspicious of the test for inherited fds disabling With some testing, CreateProcess() will not show a new console window with You can see this behavior in node as Bizarrely, the fix seems to be to launch with |
I have the same issue. https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
|
This issue is really annoying and the ticket is still open after 3 years. Any update on this? |
I've recently started seeing this after upgrading to node 16.9.1. |
This issue still persists. |
Pretty shocked that the question has been open for so long and no one cares. |
@Naozumi520 If you care about this issue, please consider working on it. That's how open-source, non-profit projects work. #21825 (comment) by @simonbuchan looks like it might be a good starting point. That being said, other comments indicate that the issue might depend on the application being spawned. |
**Problem** Storybook is showing an error message when you exit via a SIGINT. We have spent a few hours trying to understand why and work around this with no success. *Changes** 1. Conditionally disable the additional default signal listeners based on the argv contents. 2. Emit a custom event on `process` to trigger the telemetry shutdown. **Notes** I'm not really proud of this PR. Disabling based on the contents of argv isn't all that robust against false positives. Emitting a custom event on `process` is not really supposed to be done - hence why TS is complaining about the name of the signal. This work has also highlighted that on my windows 11 machine the background scripts are not firing... This was working when I updated the span values to match those found to work in this PR comment nodejs/node#21825 (comment) when I reenabled windows telemetry. Maybe something has changed, maybe it's version specific (os or node). This is an active nodejs issue so my ability to solve this in redwood code is understandably limited. Why isn't our CI finding this? We should investigate this too. @jtoar Could you confirm on mac and windows that this PR prevents those additional error messages from storybook. If you also have the time I'd appreciate if you could check if the telemetry background job is firing when you test on windows. I'll test this on ubuntu locally.
**Problem** Storybook is showing an error message when you exit via a SIGINT. We have spent a few hours trying to understand why and work around this with no success. *Changes** 1. Conditionally disable the additional default signal listeners based on the argv contents. 2. Emit a custom event on `process` to trigger the telemetry shutdown. **Notes** I'm not really proud of this PR. Disabling based on the contents of argv isn't all that robust against false positives. Emitting a custom event on `process` is not really supposed to be done - hence why TS is complaining about the name of the signal. This work has also highlighted that on my windows 11 machine the background scripts are not firing... This was working when I updated the span values to match those found to work in this PR comment nodejs/node#21825 (comment) when I reenabled windows telemetry. Maybe something has changed, maybe it's version specific (os or node). This is an active nodejs issue so my ability to solve this in redwood code is understandably limited. Why isn't our CI finding this? We should investigate this too. @jtoar Could you confirm on mac and windows that this PR prevents those additional error messages from storybook. If you also have the time I'd appreciate if you could check if the telemetry background job is firing when you test on windows. I'll test this on ubuntu locally.
I ran into this stale issue today. When encountering In light of the discussion on the web, I think the simplest solution is to run an additional node child process. for example ↓ // index.js
import { execa } from "execa";
// run node child_process
const child_process = execa("node", ["cmd.js"], {
stdio: "ignore",
shell: false,
detached: true,
windowsHide: true,
});
// quick exit, don't lock the parent process
child_process.unref(); // cmd.js
import { execa } from "execa";
import { resolve } from "path";
// static is my cmd file
await execa("static", {
cleanup: true,
stdio: "inherit"
}); Finally, execute |
I’ve thoroughly investigated this issue. Given the complexity of these parameters, I thought it would be helpful to outline some basic rules:
Based on this information, I have tested nearly every combination, and they all work as expected. |
Emm, so the UI application can hide by |
It depends on the |
sadly Windows opens cmd windows when a process is spawned as detached from the parent, and we need to detach the danser process to be able to not pass the SIGINT messages So we lose the ability to prevent the client being stopped while a render is in progress on Windows nodejs/node#21825
From what I understand, this explains it all. Closing the issue. Please reopen if needed. |
Running the following results in a command prompt popping up to run the command, and the output not being piped correctly.
Removing detached makes everything work just fine. But the command wont run if the parent dies, which is something I don't want in the actual scenario.
The text was updated successfully, but these errors were encountered: