@@ -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 ;
@@ -147,6 +159,11 @@ impl CommandExecutor for std::process::Command {
147
159
let stderr: String ;
148
160
let status: ExitStatus ;
149
161
162
+ #[ cfg( target_os = "windows" ) ]
163
+ {
164
+ self . creation_flags ( CREATE_NO_WINDOW ) ;
165
+ }
166
+
150
167
if OS == "windows" && program. as_str ( ) . ends_with ( "pg_ctl" ) {
151
168
// The pg_ctl process can hang on Windows when attempting to get stdout/stderr.
152
169
let mut process = self
@@ -188,6 +205,11 @@ impl AsyncCommandExecutor for tokio::process::Command {
188
205
let stderr: String ;
189
206
let status: ExitStatus ;
190
207
208
+ #[ cfg( target_os = "windows" ) ]
209
+ {
210
+ self . creation_flags ( CREATE_NO_WINDOW ) ;
211
+ }
212
+
191
213
if OS == "windows" && program. as_str ( ) . ends_with ( "pg_ctl" ) {
192
214
// The pg_ctl process can hang on Windows when attempting to get stdout/stderr.
193
215
let mut process = self
0 commit comments