Repository navigation
fix(process): hide console window for child processes on Windows - #139
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds the Windows Sequence diagram for Windows child process execution without a console windowsequenceDiagram
participant Caller
participant ProcessRun as process::run
participant Child as Child process
participant Console as Windows console
Caller->>ProcessRun: run(cmd, stdin, timeout)
ProcessRun->>ProcessRun: creation_flags(CREATE_NO_WINDOW)
ProcessRun->>Child: spawn()
Child-->>Console: No console window created
Sequence diagram for detached background process spawning without a console windowsequenceDiagram
participant Caller
participant State as state::spawn_detached
participant Child as Detached process
participant Console as Windows console
Caller->>State: spawn_detached(args)
State->>State: creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW)
State->>Child: spawn()
Child-->>Console: No console window created
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/process.rs" line_range="33" />
<code_context>
+ {
+ use std::os::windows::process::CommandExt;
+ const CREATE_NO_WINDOW: u32 = 0x0800_0000;
+ cmd.creation_flags(CREATE_NO_WINDOW);
+ }
let Ok(mut child) = cmd.spawn() else {
</code_context>
<issue_to_address>
**Shell-launched commands flash consoles**
When a Windows command run through `cmd.exe` launches a console application, `process::run` applies `CREATE_NO_WINDOW` only to `cmd.exe`, and that flag is not inherited by the console application it launches, so the child opens a console window and flashes.
Ensure console applications launched by `cmd.exe` also receive `CREATE_NO_WINDOW`.
</issue_to_address>
### Comment 2
<location path="src/state/mod.rs" line_range="144-145" />
<code_context>
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ const CREATE_NO_WINDOW: u32 = 0x0800_0000;
+ cmd.creation_flags(CREATE_NO_WINDOW);
+ }
</code_context>
<issue_to_address>
**Update checks still flash consoles**
When a Windows background update check reaches `curl`, `state::update::fetch` launches `curl` with `Command::output()` rather than applying `CREATE_NO_WINDOW`, so Windows opens and flashes a console during the background check.
Apply `CREATE_NO_WINDOW` to the `curl` command launched by `state::update::fetch`.
Also at `src/process.rs:33`.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: src/process.rs:33, src/state/mod.rs:145
| { | ||
| use std::os::windows::process::CommandExt; | ||
| const CREATE_NO_WINDOW: u32 = 0x0800_0000; | ||
| cmd.creation_flags(CREATE_NO_WINDOW); |
There was a problem hiding this comment.
🟡 Medium · Shell-launched commands flash consoles
When a Windows command run through cmd.exe launches a console application, process::run applies CREATE_NO_WINDOW only to cmd.exe, and that flag is not inherited by the console application it launches, so the child opens a console window and flashes.
Ensure console applications launched by cmd.exe also receive CREATE_NO_WINDOW.
Prompt for AI agents
In `src/process.rs` at line 33:
**Shell-launched commands flash consoles**
When a Windows command run through `cmd.exe` launches a console application, `process::run` applies `CREATE_NO_WINDOW` only to `cmd.exe`, and that flag is not inherited by the console application it launches, so the child opens a console window and flashes.
Ensure console applications launched by `cmd.exe` also receive `CREATE_NO_WINDOW`.
Summary
On Windows, background refreshes (such as
refresh-gitingit_cache.rsorcheck-update) are spawned withDETACHED_PROCESS. When a detached process executes a child console application (likegit status) withoutCREATE_NO_WINDOW, Windows allocates and briefly flashes a new console window on the desktop before closing it upon exit.This PR adds
CREATE_NO_WINDOW(0x0800_0000):src/process.rsfor all child processes invoked viaprocess::run.src/state/mod.rsforspawn_detached.Fixes #138
Summary by Sourcery
Bug Fixes: