@@ -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 ;
@@ -79,6 +91,11 @@ pub trait CommandBuilder: Debug {
7991 let program_file = self . get_program_file ( ) ;
8092 let mut command = std:: process:: Command :: new ( program_file) ;
8193
94+ #[ cfg( target_os = "windows" ) ]
95+ {
96+ command. creation_flags ( CREATE_NO_WINDOW ) ;
97+ }
98+
8299 command. args ( self . get_args ( ) ) ;
83100 command. envs ( self . get_envs ( ) ) ;
84101 command
@@ -93,6 +110,11 @@ pub trait CommandBuilder: Debug {
93110 let program_file = self . get_program_file ( ) ;
94111 let mut command = tokio:: process:: Command :: new ( program_file) ;
95112
113+ #[ cfg( target_os = "windows" ) ]
114+ {
115+ command. creation_flags ( CREATE_NO_WINDOW ) ;
116+ }
117+
96118 command. args ( self . get_args ( ) ) ;
97119 command. envs ( self . get_envs ( ) ) ;
98120 command
0 commit comments