Skip to content
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

Create non-console version, so conhost.exe doesn't also need to run #51

Open
xtcrefugee opened this issue Apr 8, 2023 · 3 comments
Open

Comments

@xtcrefugee
Copy link

Thank you for sol, it's working well for my needs. However, being a console app it also spawns a conhost on Windows, even when console output is directed to a file. An additional conhost consumes more memory than both sol and nssm combined, which is rather a shame as in a service configuration we don't need a console anyway.

Would it be possible to compile this as a non-console app as well, so it doesn't generate a conhost?

Many thanks for your work!

@SR-G
Copy link
Owner

SR-G commented Apr 9, 2023

I see your point, but i have no idea how to achieve that.

Do you have any evidence that it's possible / any clue about how to technically speaking achieve this ?

Because as far as i can tell, a windows program either has to be a "form-based" application (with a GUI), either a "console" application (launchable in a standalone way - and here of course with a console, or through a service machanism (here, just as a proposal, with the external tool NSSM).

And have you tried this, by the way, per the NSSM documentation ? (@see https://nssm.cc/usage)

Console window
As of version 2.22, nssm will by default create a new console window for the application. This allows some programs to work which would otherwise fail, such as those which expect to be able to read user input. The console window can be disabled if it is not needed by setting the integer (REG_DWORD) value AppNoConsole under HKLM\System\CurrentControlSet\Services\servicename\Parameters to a non-zero value.

Otherwise for reference, i have not found a lot of informations about that topic in golang :

  • this is about hiding the console (but it will still be visible inside TaskManager with a conhost.exe extra line, i would say) : https://github.com/ifrstr/hideconsole/blob/master/hideconsole_win.go
  • there is a "DETACHED_PROCESS" pure-indows property, used for example here, but not clear if this would work : https://github.com/tinygo-org/tinygo/blob/release/util_windows.go
  • there are huge golang frameworks like "https://github.com/judwhite/go-svc" (allowing to have the binaries themselves being able to register as a windows service), but a) i don't know if that would work anyway (about not having a "conhost.exe" associated process) and b) i really don't like this approach, which is not at all going in the good direction (wrapping as a service should be done around the processes ("unix philosophy"), and not with a lot of code inside the processes themselves)

@xtcrefugee
Copy link
Author

xtcrefugee commented Apr 9, 2023

Sorry, I have no experience with Go so I don't know if it's possible within that framework.

The closest thing I can think of, with an app that stays resident but has no console window, would be something like a compiled AutoHotkey script. Those have a system tray icon to (minimally) just exit the program. I don't know if that's something you'd consider replicating here or not.

Unfortunately I'd already tried setting NSSM to not have a console window (it's also a checkbox in NSSM's interactive UI) but sol still spawns one. I also tried redirecting stdin and stdout to <NUL and >NUL respectively, but the console process still starts.

@skrimix
Copy link
Contributor

skrimix commented May 20, 2023

Adding -ldflags -H=windowsgui to go build command produces a GUI executable and Windows stops allocating console automatically. I tested with NSSM and sol is working without spawning conhost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants