Launch
This commit is contained in:
23
internal/oscmd/command.go
Normal file
23
internal/oscmd/command.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package oscmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// Command creates an exec.Cmd with platform-specific defaults that are safe for
|
||||
// the GUI application. On Windows, the implementation hides child console
|
||||
// windows so helpers like powershell.exe, netsh.exe, route.exe, xray.exe, and
|
||||
// dnstt-client.exe do not flash a terminal window.
|
||||
func Command(name string, args ...string) *exec.Cmd {
|
||||
cmd := exec.Command(name, args...)
|
||||
applyPlatformOptions(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// CommandContext is the context-aware version of Command.
|
||||
func CommandContext(ctx context.Context, name string, args ...string) *exec.Cmd {
|
||||
cmd := exec.CommandContext(ctx, name, args...)
|
||||
applyPlatformOptions(cmd)
|
||||
return cmd
|
||||
}
|
||||
7
internal/oscmd/command_other.go
Normal file
7
internal/oscmd/command_other.go
Normal file
@@ -0,0 +1,7 @@
|
||||
//go:build !windows
|
||||
|
||||
package oscmd
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func applyPlatformOptions(cmd *exec.Cmd) {}
|
||||
17
internal/oscmd/command_windows.go
Normal file
17
internal/oscmd/command_windows.go
Normal file
@@ -0,0 +1,17 @@
|
||||
//go:build windows
|
||||
|
||||
package oscmd
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const createNoWindow = 0x08000000
|
||||
|
||||
func applyPlatformOptions(cmd *exec.Cmd) {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
HideWindow: true,
|
||||
CreationFlags: createNoWindow,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user