@@ -2,11 +2,23 @@ use crate::error::{Error, Result};
2
2
use std:: env:: consts:: OS ;
3
3
use std:: ffi:: { OsStr , OsString } ;
4
4
use std:: fmt:: Debug ;
5
+ #[ cfg( target_os = "windows" ) ]
6
+ use std:: os:: windows:: process:: CommandExt ;
5
7
use std:: path:: PathBuf ;
6
8
use std:: process:: ExitStatus ;
7
9
use std:: time:: Duration ;
8
10
use tracing:: debug;
9
11
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
+
10
22
/// Interface for `PostgreSQL` settings
11
23
pub trait Settings {
12
24
fn get_binary_dir ( & self ) -> PathBuf ;
@@ -79,6 +91,11 @@ pub trait CommandBuilder: Debug {
79
91
let program_file = self . get_program_file ( ) ;
80
92
let mut command = std:: process:: Command :: new ( program_file) ;
81
93
94
+ #[ cfg( target_os = "windows" ) ]
95
+ {
96
+ command. creation_flags ( CREATE_NO_WINDOW ) ;
97
+ }
98
+
82
99
command. args ( self . get_args ( ) ) ;
83
100
command. envs ( self . get_envs ( ) ) ;
84
101
command
@@ -93,6 +110,11 @@ pub trait CommandBuilder: Debug {
93
110
let program_file = self . get_program_file ( ) ;
94
111
let mut command = tokio:: process:: Command :: new ( program_file) ;
95
112
113
+ #[ cfg( target_os = "windows" ) ]
114
+ {
115
+ command. creation_flags ( CREATE_NO_WINDOW ) ;
116
+ }
117
+
96
118
command. args ( self . get_args ( ) ) ;
97
119
command. envs ( self . get_envs ( ) ) ;
98
120
command
0 commit comments