@@ -2,11 +2,23 @@ use crate::error::{Error, Result};
22use std:: env:: consts:: OS ;
33use std:: ffi:: { OsStr , OsString } ;
44use std:: fmt:: Debug ;
5+ #[ cfg( target_os="windows" ) ]
6+ use std:: os:: windows:: process:: CommandExt ;
57use std:: path:: PathBuf ;
68use std:: process:: ExitStatus ;
79use std:: time:: Duration ;
810use tracing:: debug;
911
12+ /// Constant for the `CREATE_NO_WINDOW` flag on Windows to prevent the creation of a console window
13+ /// when executing commands. This is useful for background processes or services that do not require
14+ /// user interaction.
15+ ///
16+ /// # References
17+ ///
18+ /// - [Windows API: Process Creation Flags](https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags#flags)
19+ #[ cfg( target_os="windows" ) ]
20+ const CREATE_NO_WINDOW : u32 = 0x0800_0000 ;
21+
1022/// Interface for `PostgreSQL` settings
1123pub trait Settings {
1224 fn get_binary_dir ( & self ) -> PathBuf ;
@@ -147,6 +159,11 @@ impl CommandExecutor for std::process::Command {
147159 let stderr: String ;
148160 let status: ExitStatus ;
149161
162+ #[ cfg( target_os = "windows" ) ]
163+ {
164+ self . creation_flags ( CREATE_NO_WINDOW ) ;
165+ }
166+
150167 if OS == "windows" && program. as_str ( ) . ends_with ( "pg_ctl" ) {
151168 // The pg_ctl process can hang on Windows when attempting to get stdout/stderr.
152169 let mut process = self
@@ -188,6 +205,11 @@ impl AsyncCommandExecutor for tokio::process::Command {
188205 let stderr: String ;
189206 let status: ExitStatus ;
190207
208+ #[ cfg( target_os = "windows" ) ]
209+ {
210+ self . creation_flags ( CREATE_NO_WINDOW ) ;
211+ }
212+
191213 if OS == "windows" && program. as_str ( ) . ends_with ( "pg_ctl" ) {
192214 // The pg_ctl process can hang on Windows when attempting to get stdout/stderr.
193215 let mut process = self
0 commit comments