From ac43cdea703eefac7a64e1452a6475ea47b47cf0 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 24 Oct 2026 20:25:40 +0200 Subject: [PATCH] launcher, server: one hidden-command helper per crate, server children keep its terminal - horizon-bench reads the machine with horizon-telemetry's `command_output` (now public) instead of a second copy of it; the console flag lives in one place. - horizon-server's `process::command` hides the console only when the server has none (started by the launcher). Run from a terminal, `schtasks`, `tar` and `mklink` share it as before, so their output still reaches it: a CREATE_NO_WINDOW child can't write to its parent's console. - horizon-prepare's java/javac keep the stdin they had; only the console flag is new. - launcher `process::hide_console` returns the command (no `let _ =` on other systems); the machine-details thread failing just leaves the report without them, as a slow one does. - README: the Windows subsystem's effect on the command line (interactive cmd/PowerShell don't wait or set the exit code) under "Command line", the deferred probe under "Performance log". Co-Authored-By: Claude Opus 5.5 --- crates/horizon-bench/src/hardware.rs | 17 +--------------- crates/horizon-prepare/src/java.rs | 11 +++++----- crates/horizon-server/src/process.rs | 28 ++++++++++++++------------ crates/horizon-telemetry/src/system.rs | 5 ++++- launcher/README.md | 17 ++++++++-------- launcher/src/perf.rs | 8 ++------ launcher/src/process.rs | 11 +++++----- 7 files changed, 41 insertions(+), 56 deletions(-) diff --git a/crates/horizon-bench/src/hardware.rs b/crates/horizon-bench/src/hardware.rs index 6b91202ad..440c834d8 100644 --- a/crates/horizon-bench/src/hardware.rs +++ b/crates/horizon-bench/src/hardware.rs @@ -1,8 +1,7 @@ //! The machine a report was measured on. CPU, RAM and OS are detected here; the GPU and the display //! come from the program that rendered (the game knows its adapter, the launcher its window). -use std::process::Command; - +use horizon_telemetry::system::command_output as output; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] @@ -173,20 +172,6 @@ pub fn cpu_seconds(pid: u32) -> Option { Some(ticks / 100.0) } -fn output(program: &str, args: &[&str]) -> Option { - let mut command = Command::new(program); - command.args(args); - #[cfg(windows)] - { - use std::os::windows::process::CommandExt; - const CREATE_NO_WINDOW: u32 = 0x0800_0000; - command.creation_flags(CREATE_NO_WINDOW); - } - let out = command.output().ok()?; - let text = String::from_utf8(out.stdout).ok()?.trim().to_owned(); - (out.status.success() && !text.is_empty()).then_some(text) -} - #[cfg(target_os = "macos")] fn os_version() -> Option { output("sw_vers", &["-productVersion"]) diff --git a/crates/horizon-prepare/src/java.rs b/crates/horizon-prepare/src/java.rs index 78530486c..b4023b7d1 100644 --- a/crates/horizon-prepare/src/java.rs +++ b/crates/horizon-prepare/src/java.rs @@ -14,16 +14,17 @@ pub struct Jdk { const TIMEOUT: Duration = Duration::from_secs(3600); -/// Exporters and JDK probes write to pipes or log files, never to a new terminal. +/// Exporters and JDK probes write to pipes or log files: on Windows they open no terminal. fn command(program: impl AsRef) -> Command { - let mut command = Command::new(program); - command.stdin(Stdio::null()); + let command = Command::new(program); #[cfg(windows)] - { + let command = { use std::os::windows::process::CommandExt; const CREATE_NO_WINDOW: u32 = 0x0800_0000; + let mut command = command; command.creation_flags(CREATE_NO_WINDOW); - } + command + }; command } diff --git a/crates/horizon-server/src/process.rs b/crates/horizon-server/src/process.rs index 8a79f1161..8e8d24c70 100644 --- a/crates/horizon-server/src/process.rs +++ b/crates/horizon-server/src/process.rs @@ -1,18 +1,20 @@ -//! Background helpers inherit their log streams without opening a Windows terminal. +//! The programs the server runs. Started by the launcher, the server has no console, and each +//! console program it started would open a terminal window on Windows: those open none. Run from +//! a terminal, they share it, so what they print still reaches it. use std::{ffi::OsStr, process::Command}; pub fn command(program: impl AsRef) -> Command { - let mut command = Command::new(program); - configure(&mut command); + let command = Command::new(program); + #[cfg(windows)] + let command = { + use std::os::windows::process::CommandExt; + use windows_sys::Win32::System::{Console::GetConsoleWindow, Threading::CREATE_NO_WINDOW}; + let mut command = command; + // SAFETY: no arguments; it returns this process's console window or null. + if unsafe { GetConsoleWindow() }.is_null() { + command.creation_flags(CREATE_NO_WINDOW); + } + command + }; command } - -fn configure(command: &mut Command) { - #[cfg(windows)] - { - use std::os::windows::process::CommandExt; - command.creation_flags(windows_sys::Win32::System::Threading::CREATE_NO_WINDOW); - } - #[cfg(not(windows))] - let _ = command; -} diff --git a/crates/horizon-telemetry/src/system.rs b/crates/horizon-telemetry/src/system.rs index 33a5b744d..8ed6f2e3a 100644 --- a/crates/horizon-telemetry/src/system.rs +++ b/crates/horizon-telemetry/src/system.rs @@ -9,7 +9,10 @@ use std::sync::OnceLock; use crate::payload::System; -fn command_output(program: &str, args: &[&str]) -> Option { +/// What `program args` prints, trimmed, when it succeeds and prints something. On Windows the +/// program opens no console window: a GUI launcher or a game started without one would flash a +/// terminal for every probe. +pub fn command_output(program: &str, args: &[&str]) -> Option { let mut command = std::process::Command::new(program); command.args(args); #[cfg(windows)] diff --git a/launcher/README.md b/launcher/README.md index d2b78daea..d9738d0c2 100644 --- a/launcher/README.md +++ b/launcher/README.md @@ -97,12 +97,6 @@ page `servers.json` (the list), `servers//` (the servers created there) an Long pages, dialogs, the server console and data previews have a visible scrollbar when their content overflows. Drag the thumb or click the track to navigate without a mouse wheel. -On Windows, desktop launches and background tools run without terminal windows. Preparation -and server logs still reach the launcher, and CLI commands keep their terminal or redirected -input and output, including MCP. -Hardware details for performance reports are collected in the background after the first -frame, so Windows hardware queries do not delay the window opening. - ## Updates The launcher looks for a newer Horizon release when it starts and every 30 minutes while it @@ -133,7 +127,12 @@ and `horizon-launcher-windows-x64.zip`, never marked latest. The version is buil ## Command line -The same binary is a command-line tool; without a subcommand it opens the window. +The same binary is a command-line tool; without a subcommand it opens the window. On Windows it +is a windowed program, so a desktop start opens no terminal; a subcommand writes to the terminal +it was typed in, or to the pipes and files it was given (MCP keeps its stdio). Interactive `cmd` +and PowerShell don't wait for a windowed program: they show the prompt again before its output +and don't set `%ERRORLEVEL%` / `$LASTEXITCODE`. Scripts that need the exit code use +`start /wait horizon-launcher …` or `Start-Process -Wait`, or read its output through a pipe. horizon-launcher versions [--installed] releases on GitHub, or what is installed (* = selected) horizon-launcher install @@ -256,8 +255,8 @@ Each session writes its own measurements to `benchmarks/launcher-