diff --git a/crates/horizon-bench/src/hardware.rs b/crates/horizon-bench/src/hardware.rs index 17e460bed..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,12 +172,6 @@ pub fn cpu_seconds(pid: u32) -> Option { Some(ticks / 100.0) } -fn output(program: &str, args: &[&str]) -> Option { - let out = Command::new(program).args(args).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-bench/src/lib.rs b/crates/horizon-bench/src/lib.rs index bdc885af1..ae70977bd 100644 --- a/crates/horizon-bench/src/lib.rs +++ b/crates/horizon-bench/src/lib.rs @@ -245,13 +245,19 @@ pub struct Report { impl Report { /// An empty report for this machine, created now. pub fn new(kind: Kind, app: App) -> Report { + Self::with_hardware(kind, app, Hardware::detect()) + } + + /// Starts a report using supplied hardware, without running system probes. + /// Interactive apps can collect the remaining machine details after their first frame. + pub fn with_hardware(kind: Kind, app: App, hardware: Hardware) -> Report { Report { format: FORMAT.to_owned(), version: VERSION, kind, created: utc_now(), app, - hardware: Hardware::detect(), + hardware, conditions: Conditions::default(), metrics: BTreeMap::new(), frames: Vec::new(), diff --git a/crates/horizon-prepare/src/java.rs b/crates/horizon-prepare/src/java.rs index a159fb055..b4023b7d1 100644 --- a/crates/horizon-prepare/src/java.rs +++ b/crates/horizon-prepare/src/java.rs @@ -1,6 +1,7 @@ //! The JDK that compiles and runs the vanilla exporters. They call Mojang's own code, so they //! stay Java; everything around them is here. +use std::ffi::OsStr; use std::fs; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; @@ -13,6 +14,20 @@ pub struct Jdk { const TIMEOUT: Duration = Duration::from_secs(3600); +/// Exporters and JDK probes write to pipes or log files: on Windows they open no terminal. +fn command(program: impl AsRef) -> Command { + 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 +} + fn executable(dir: &Path, name: &str) -> PathBuf { dir.join(if cfg!(windows) { format!("{name}.exe") @@ -29,7 +44,7 @@ fn on_path(name: &str) -> Option { /// The major version `javac -version` reports ("javac 25.0.1" → 25; "javac 1.8.0" → 8). fn javac_major(javac: &Path) -> Result { - let output = Command::new(javac) + let output = command(javac) .arg("-version") .stdin(Stdio::null()) .output() @@ -183,7 +198,7 @@ pub fn find(major: i64, more: &[PathBuf]) -> Result { candidates.push((javac, java, "PATH")); } if cfg!(target_os = "macos") { - if let Ok(out) = Command::new("/usr/libexec/java_home") + if let Ok(out) = command("/usr/libexec/java_home") .args(["-v", &major.to_string()]) .stderr(Stdio::null()) .output() @@ -260,7 +275,7 @@ impl Jdk { /// `javac --release -proc:none` with Python's `subprocess.run(..., check=True, /// stdout=log, stderr=STDOUT, timeout=3600)`. pub fn javac(&self, major: i64, args: &[String], log: &fs::File) -> Result<(), String> { - let mut command = Command::new(&self.javac); + let mut command = command(&self.javac); command .args(["--release", &major.to_string(), "-proc:none"]) .args(args); @@ -268,7 +283,7 @@ impl Jdk { } pub fn java(&self, args: &[String], cwd: Option<&Path>, log: &fs::File) -> Result<(), String> { - let mut command = Command::new(&self.java); + let mut command = command(&self.java); command.args(args); if let Some(dir) = cwd { command.current_dir(dir); diff --git a/crates/horizon-server/src/engine.rs b/crates/horizon-server/src/engine.rs index 051ae77f0..fd7c86321 100644 --- a/crates/horizon-server/src/engine.rs +++ b/crates/horizon-server/src/engine.rs @@ -68,7 +68,8 @@ pub fn program_in( /// system can't load the program, as on a Linux without the ALSA and udev libraries the full game links /// (the server build doesn't). The reason, with what to install. pub fn check_starts(program: &Path) -> Result<(), String> { - let output = Command::new(program) + let mut command = crate::process::command(program); + let output = command .arg("--help") .stdin(Stdio::null()) .stdout(Stdio::null()) @@ -176,7 +177,8 @@ pub fn spawn(program: &Path, resources: &Path, dir: &Path) -> std::io::Result) -> 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 +} diff --git a/crates/horizon-server/src/service.rs b/crates/horizon-server/src/service.rs index 6e6d59f23..96b9f218f 100644 --- a/crates/horizon-server/src/service.rs +++ b/crates/horizon-server/src/service.rs @@ -178,7 +178,7 @@ fn systemd_path(service: &str, system: bool) -> Result { } fn run(program: &str, args: &[&str]) -> Result<(), String> { - let status = Command::new(program) + let status = crate::process::command(program) .args(args) .status() .map_err(|e| format!("{program}: {e}"))?; @@ -191,7 +191,7 @@ fn run(program: &str, args: &[&str]) -> Result<(), String> { /// A step that may fail harmlessly (stopping what isn't running): its output would only alarm. fn quiet(program: &str, args: &[&str]) { - let _ = Command::new(program) + let _ = crate::process::command(program) .args(args) .stdout(std::process::Stdio::null()) .stderr(std::process::Stdio::null()) diff --git a/crates/horizon-server/src/update.rs b/crates/horizon-server/src/update.rs index cbcfe637e..8c87c66bc 100644 --- a/crates/horizon-server/src/update.rs +++ b/crates/horizon-server/src/update.rs @@ -10,7 +10,6 @@ use serde_json::{Value, json}; use std::{ io::Read, path::{Path, PathBuf}, - process::Command, time::{Duration, Instant}, }; @@ -206,7 +205,7 @@ fn point(link: &Path, target: &Path) -> std::io::Result<()> { if link.exists() || link.symlink_metadata().is_ok() { std::fs::remove_dir(link)?; } - let status = Command::new("cmd") + let status = crate::process::command("cmd") .arg("/C") .arg("mklink") .arg("/J") @@ -474,7 +473,7 @@ pub fn unpack(install: &Install, archive: &Path, tag: &str) -> Result Option { - let out = std::process::Command::new(program) - .args(args) - .output() - .ok()?; +/// 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)] + { + 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_lossy(&out.stdout).trim().to_owned(); (out.status.success() && !text.is_empty()).then_some(text) } diff --git a/launcher/README.md b/launcher/README.md index d9d51cb36..1c0ea5522 100644 --- a/launcher/README.md +++ b/launcher/README.md @@ -131,7 +131,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 @@ -254,8 +259,8 @@ Each session writes its own measurements to `benchmarks/launcher-