From 54a1b66b949c455b4ea33083a3049c548f624f29 Mon Sep 17 00:00:00 2001 From: "d3c0d3d.exe" <0xc0d32@gmail.com> Date: Tue, 21 Mar 2023 06:24:40 -0300 Subject: [PATCH] os: add create_no_window parameter to Process (#17726) --- vlib/os/process.v | 17 +++++++++-------- vlib/os/process_windows.c.v | 6 +++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/vlib/os/process.v b/vlib/os/process.v index d4a6e7292d..eba58ca5c9 100644 --- a/vlib/os/process.v +++ b/vlib/os/process.v @@ -25,14 +25,15 @@ pub mut: // the exit code of the process, != -1 *only* when status is .exited *and* the process was not aborted status ProcessState = .not_started // the current status of the process - err string // if the process fails, contains the reason why - args []string // the arguments that the command takes - env_is_custom bool // true, when the environment was customized with .set_environment - env []string // the environment with which the process was started (list of 'var=val') - use_stdio_ctl bool // when true, then you can use p.stdin_write(), p.stdout_slurp() and p.stderr_slurp() - use_pgroup bool // when true, the process will create a new process group, enabling .signal_pgkill() - stdio_fd [3]int // the stdio file descriptors for the child process, used only by the nix implementation - wdata voidptr // the WProcess; used only by the windows implementation + err string // if the process fails, contains the reason why + args []string // the arguments that the command takes + env_is_custom bool // true, when the environment was customized with .set_environment + env []string // the environment with which the process was started (list of 'var=val') + use_stdio_ctl bool // when true, then you can use p.stdin_write(), p.stdout_slurp() and p.stderr_slurp() + use_pgroup bool // when true, the process will create a new process group, enabling .signal_pgkill() + stdio_fd [3]int // the stdio file descriptors for the child process, used only by the nix implementation + wdata voidptr // the WProcess; used only by the windows implementation + create_no_window bool // sets a value indicating whether to start the process in a new window, The default is false; used only by the windows implementation } // new_process - create a new process descriptor diff --git a/vlib/os/process_windows.c.v b/vlib/os/process_windows.c.v index 6f894e3217..def17d62f7 100644 --- a/vlib/os/process_windows.c.v +++ b/vlib/os/process_windows.c.v @@ -97,7 +97,11 @@ fn (mut p Process) win_spawn_process() int { cmd := '${p.filename} ' + p.args.join(' ') C.ExpandEnvironmentStringsW(cmd.to_wide(), voidptr(&wdata.command_line[0]), 32768) - mut creation_flags := int(C.NORMAL_PRIORITY_CLASS) + mut creation_flags := if p.create_no_window { + int(C.CREATE_NO_WINDOW) + } else { + int(C.NORMAL_PRIORITY_CLASS) + } if p.use_pgroup { creation_flags |= C.CREATE_NEW_PROCESS_GROUP }