mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
portlist: set SysProcAttr.HideWindow on Windows
Prevents annoying shell window flashes when running /server by hand.
This commit is contained in:
parent
07ca0c1c29
commit
2ca2389c5f
@ -13,12 +13,22 @@
|
||||
exec "tailscale.com/tempfork/osexec"
|
||||
)
|
||||
|
||||
var osHideWindow func(*exec.Cmd) // non-nil on Windows; see portlist_windows.go
|
||||
|
||||
// hideWindow returns c. On Windows it first sets SysProcAttr.HideWindow.
|
||||
func hideWindow(c *exec.Cmd) *exec.Cmd {
|
||||
if osHideWindow != nil {
|
||||
osHideWindow(c)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func listPortsNetstat(arg string) (List, error) {
|
||||
exe, err := exec.LookPath("netstat")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("netstat: lookup: %v", err)
|
||||
}
|
||||
output, err := exec.Command(exe, arg).Output()
|
||||
output, err := hideWindow(exec.Command(exe, arg)).Output()
|
||||
if err != nil {
|
||||
xe, ok := err.(*exec.ExitError)
|
||||
stderr := ""
|
||||
|
@ -5,7 +5,10 @@
|
||||
package portlist
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
exec "tailscale.com/tempfork/osexec"
|
||||
)
|
||||
|
||||
// Forking on Windows is insanely expensive, so don't do it too often.
|
||||
@ -18,3 +21,9 @@ func listPorts() (List, error) {
|
||||
func addProcesses(pl []Port) ([]Port, error) {
|
||||
return listPortsNetstat("-nab")
|
||||
}
|
||||
|
||||
func init() {
|
||||
osHideWindow = func(c *exec.Cmd) {
|
||||
c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user