@@ -10,6 +10,7 @@ import (
1010 "net/http"
1111 "os"
1212 "os/exec"
13+ "runtime"
1314 "strings"
1415 "sync"
1516 "time"
@@ -49,19 +50,18 @@ func main() {
4950 var cmd * exec.Cmd
5051 var configFile * os.File
5152
52- if c .Protocol == "hysteria" || c .Protocol == "hysteria2" || c .Protocol == "hy2" {
53+ ctx , cancel := context .WithTimeout (context .Background (), 15 * time .Second )
54+ defer cancel ()
5355
56+ if c .Protocol == "hysteria" || c .Protocol == "hysteria2" {
5457 configFile , err = os .CreateTemp ("" , "hysteria-*.json" )
5558 if err != nil { results <- TestResult {Tag : c .Tag , Ping : - 1 , Status : "tempfile_error" }; return }
5659 defer os .Remove (configFile .Name ())
57-
5860 configFile .Write (c .Config )
5961 configFile .Close ()
60-
61- cmd = exec .Command (c .ClientPath , "client" , "-c" , configFile .Name ())
62+ cmd = exec .CommandContext (ctx , c .ClientPath , "client" , "-c" , configFile .Name ())
6263
6364 } else {
64-
6565 configFile , err = os .CreateTemp ("" , "xray-*.json" )
6666 if err != nil { results <- TestResult {Tag : c .Tag , Ping : - 1 , Status : "tempfile_error" }; return }
6767 defer os .Remove (configFile .Name ())
@@ -82,13 +82,13 @@ func main() {
8282 configFile .Write (configBytes )
8383 configFile .Close ()
8484
85- cmd = exec .Command ( c .ClientPath , "-c" , configFile .Name ())
85+ cmd = exec .CommandContext ( ctx , c .ClientPath , "-c" , configFile .Name ())
8686 }
8787
88- ctx , cancel := context . WithTimeout ( context . Background (), 15 * time . Second )
89- defer cancel ()
90- cmd . SysProcAttr = & exec. SysProcAttr { HideWindow : true }
91- cmd . Cancel = func () error { return cmd . Process . Kill () }
88+
89+ if runtime . GOOS == "windows" {
90+ setHideWindow ( cmd )
91+ }
9292
9393 var clientOutput bytes.Buffer
9494 cmd .Stdout = & clientOutput
0 commit comments