Silent Mode execution
Not an issue, but a feature request.
Since it very usefull to use iojs as script interpreter, the one feature is missing, and I can suggest that many can vote for it - execute script without console window showing.
I'm not really a programmer, and cannot even say is it possible or not to make console application start without creating a window. But if it is possible I think it may be very usefull to have some command line switch, like --background or --hidden to get this stuff.
Another approach to this can be via another executable, for example windows has wscript.exe and cscript.exe to execute scripts in different modes.
Maybe this was discussed and rejected a lot of time in Node project, but since IOJS is a different project I just want to try again =) I know there is a lot of stuff to get this done like binaries that executes console apps in hidden mode, but this is such a little and such a usefull feature so having it bundled within iojs executable will be really awesome, since we don't need another tool for that.
For example: I need my JS script to execute some program, wait for it's finish, and do some stuff after that, maybe depend on exit code or something like that, so I can spawn a new process from script and give it a callback. They key here is that I don't want to see any windows, neither spawned process, nor iojs. And I will not see spawned process, but will see iojs window for all the time the spawned process will work. So this is a bit frustrating.
So my question is: Is this feature can be accepted for consideration by new TC or not?
And if not, can you please provide some info how I can recompile iojs executable to get it run completely silent?
I don't think --interactive needs to do anything from this "silent mode".
Add --dest-windows-subsystem={console,windows} configure option (and vcbuild.bat equivalent)
Sounds good. Will --subsystem=windows build nodew.exe ?
Create dummy stdio streams when console is not available
Sounds good but I'd like to hear a little bit more about how you're planning to replace the dummy streams by an actual console when it is attached later.
Sounds good. Will --subsystem=windows build nodew.exe?
If that's what we want then sure!
Sounds good but I'd like to hear a little bit more about how you're planning to replace the dummy streams by an actual console when it is attached later.
In my local patches, using nodew.exe --interactive will allocate a console early in the startup just to make debugging easier if all you have is nodew.exe. We would not react to a console being attached after startup. @piscisaureus, does that sound reasonable?
In normal circumstances of running nodejs console window is expected (save background processes that are typically handled differently) but, with GUI libraries such as electron, console window could become annoying and unwanted. Any solution will work for me. Ideally (thinking aloud) it could be a binary argument option on command line (if that is possible) defaulting to use console window if not specified and not use when specified (something like --noconsole)
:+1: nodew.exe
For newbies like me coming here, as OP proposed it's possible for the moment to run Node with hidden console using wscript.
Save something like this with .vbs extension and execute it.
Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c node app.js" ' or Wscript.Arguments(0)
oShell.Run strArgs, 0, false
You'll have to kill Node using Task manager or from your script itself. Source: http://superuser.com/a/140077/156509
As workaround I tried this:
var spawn = require('child_process').spawn
spawn(process.argv0, ['.'], {stdio: 'ignore', detached: true})
process.exit(0);
Console pops and immediately closes. Spawned process runs in background without console.
And it is really simple to make nodew.exe - it is a matter of patching one byte (from 3 to 2).
Nevertheless, it would be quite convenient to have nodew.exe along with node.exe out of box. May be installer can generate the former on the fly.
Has there been movement on this or anything related to it lately? I think @refack might have been talking about something like this? Should this remain open? @nodejs/platform-windows I guess?
IMHO it should stay open. Ref: https://github.com/nodejs/node/issues/14158
+1 I use OpenGL window, and if I were to release any kind of product based on it, I'd rather prefere to hide an ugly black console from the end-user
Some people helped themselves with a custom built node.exe -> https://stackoverflow.com/questions/22653010/prevent-console-window-from-being-created-in-custom-node-js-build/22653825#22653825
I've been maintaining a patch to do this for our custom Node build. Here is an up-to-date patch for Node 8.9.x: https://gist.github.com/poiru/d7cedb2c3c4c7aca9dce29d439597cca
Custom build is too complex desision for me. It's the matter of patching node.exe, changing one byte of exe-file from 03 to 02. Et voila!
Thanks @ukoloff for the tip, I've dockerized the generation of nodew.exe with https://github.com/StefanScherer/dockerfiles-windows/pull/275
Since I also had a need for this in one of my projects, I ported @ukoloff's solution (Thank you very much for posting it!) to node and released it as a standalone solution that offers both CLI and API: https://www.npmjs.com/package/create-nodew-exe
Closing this because there's a solution available in the userland (thanks, @s-h-a-d-o-w). Feel free to reopen this.
@ryzokuken
Uhm, thanks but I was actually hoping for an official solution at some point because the solution implemented by @ukoloff and me is a pretty dirty hack, as is noticeable by the fact that when you start an app using such a modified .exe, the mouse cursor will switch to "busy" state for like 5-6 seconds.
Which obviously makes for questionable UX, as the user will rightfully ask themselves "What the hell is that thing doing?", as node doesn't actually take 5-6 seconds to start up.
@s-h-a-d-o-w FWIW, the node_main.cc patch in my earlier comment addresses the feedback cursor as well.
Yeah I saw that but... as that can't be automated (at least I don't think so, as the code base may change, so you always need to check manually?), I find it too much of a hassle to deal with especially for small personal projects.
If you work at a company where you're free to spend an hour here or there building silent executables for every node version that is being used, it's different. Still annoying I imagine but... at least you get paid to do it. :wink: