Skip to content

Commit df10999

Browse files
committed
fix: set CREATE_NO_WINDOW creation flag on Windows
1 parent 5423e5c commit df10999

File tree

3 files changed

+122
-27
lines changed

3 files changed

+122
-27
lines changed

Cargo.lock

Lines changed: 98 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ anyhow = "1.0.98"
2929
async-trait = "0.1.88"
3030
axum = "0.8.4"
3131
criterion = "0.6.0"
32-
diesel = "2.2.10"
32+
diesel = "2.2.11"
3333
diesel_migrations = "2.2.0"
3434
flate2 = "1.1.2"
3535
futures-util = "0.3.31"
3636
hex = "0.4.3"
3737
indicatif = "0.17.11"
3838
indoc = "2.0.6"
39-
liblzma = "0.4.1"
39+
liblzma = "0.4.2"
4040
md-5 = "0.10.6"
4141
num-format = "0.4.4"
4242
pgvector = "0.4.1"

postgresql_commands/src/traits.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@ use crate::error::{Error, Result};
22
use std::env::consts::OS;
33
use std::ffi::{OsStr, OsString};
44
use std::fmt::Debug;
5+
#[cfg(target_os = "windows")]
6+
use std::os::windows::process::CommandExt;
57
use std::path::PathBuf;
68
use std::process::ExitStatus;
79
use std::time::Duration;
810
use 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
1123
pub 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

Comments
 (0)