Skip to main content

Module console

Module console 

Source
Expand description

A console shim for a Windows GUI binary.

An app’s GUI binary is built for the Windows GUI subsystem and has no console, so a typed command prints nothing and returns at once. A tiny console binary on PATH calls [forward]: it starts the GUI binary with the same arguments and standard streams, waits, and exits with its exit code.

On Windows the child is put in a job object that kills it when the shim goes away, so Ctrl+C in the console takes the GUI process with it. Only the child: the job lets the processes it starts leave silently (JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK). Velopack starts its Update.exe without asking to leave the job, and the GUI exits for the update to be applied; in the shim’s job, Update.exe would be killed with it halfway through replacing the files, and so would the app it restarts and any daemon.

A shim has no logging set up, so a job that cannot be made is reported on standard error.

A binary without the shim (installed with cargo install, or run before there is a package) calls corundum_framework_platform::console::attach_parent instead, on its command-line starts only (not the one that opens the window): its output then reaches the terminal it was started from, but the shell does not wait for it, so its exit code and typed input are lost. The shim stays the full command line.

Functions§

forward_to
Runs exe with args and this process’s standard streams, waits, and returns its exit code (1 when it ended without one or could not start).