You could use std::os::windows::process::CommandExt::creation_flags
. Please refer to the documentation page for the Process Creation Flags or ideally use the constants from winapi.
You wrote that this is a GUI application, so I assume you don't need the console output on this one. DETACHED_PROCESS
does not create conhost.exe, but if you want to process the output you should use CREATE_NO_WINDOW
.
I would also recommend using start
as the command because otherwise you will have to use cmd.exe
and this will probably delay the start by a few milliseconds.
Example
use std::process::Command;
use std::os::windows::process::CommandExt;
const CREATE_NO_WINDOW: u32 = 0x08000000;
const DETACHED_PROCESS: u32 = 0x00000008;
let mut command = Command::new("cmd").args(&["/C", "start", &exe_path]);
command.creation_flags(DETACHED_PROCESS); // Be careful: This only works on windows
// If you use DETACHED_PROCESS you could set stdout, stderr, and stdin to Stdio::null() to avoid possible allocations.
CREATE_NO_WINDOW
flag (will be no window, but will be console(invisible) created for process) orDETACHED_PROCESS
- will be no console at all. this more efficient compare withCREATE_NO_WINDOW
flag (will be no additional conhost.exe) but application can exit, if it assume console handles exist and work