Skip to content

fix: set CREATE_NO_WINDOW creation flag on Windows #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 98 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ anyhow = "1.0.98"
async-trait = "0.1.88"
axum = "0.8.4"
criterion = "0.6.0"
diesel = "2.2.10"
diesel = "2.2.11"
diesel_migrations = "2.2.0"
flate2 = "1.1.2"
futures-util = "0.3.31"
hex = "0.4.3"
indicatif = "0.17.11"
indoc = "2.0.6"
liblzma = "0.4.1"
liblzma = "0.4.2"
md-5 = "0.10.6"
num-format = "0.4.4"
pgvector = "0.4.1"
Expand Down
22 changes: 22 additions & 0 deletions postgresql_commands/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ use crate::error::{Error, Result};
use std::env::consts::OS;
use std::ffi::{OsStr, OsString};
use std::fmt::Debug;
#[cfg(target_os = "windows")]
use std::os::windows::process::CommandExt;
use std::path::PathBuf;
use std::process::ExitStatus;
use std::time::Duration;
use tracing::debug;

/// Constant for the `CREATE_NO_WINDOW` flag on Windows to prevent the creation of a console window
/// when executing commands. This is useful for background processes or services that do not require
/// user interaction.
///
/// # References
///
/// - [Windows API: Process Creation Flags](https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags#flags)
#[cfg(target_os = "windows")]
const CREATE_NO_WINDOW: u32 = 0x0800_0000;

/// Interface for `PostgreSQL` settings
pub trait Settings {
fn get_binary_dir(&self) -> PathBuf;
Expand Down Expand Up @@ -79,6 +91,11 @@ pub trait CommandBuilder: Debug {
let program_file = self.get_program_file();
let mut command = std::process::Command::new(program_file);

#[cfg(target_os = "windows")]
{
command.creation_flags(CREATE_NO_WINDOW);
}

command.args(self.get_args());
command.envs(self.get_envs());
command
Expand All @@ -93,6 +110,11 @@ pub trait CommandBuilder: Debug {
let program_file = self.get_program_file();
let mut command = tokio::process::Command::new(program_file);

#[cfg(target_os = "windows")]
{
command.creation_flags(CREATE_NO_WINDOW);
}

command.args(self.get_args());
command.envs(self.get_envs());
command
Expand Down