Skip to content

Commit 8bad636

Browse files
authored
Merge pull request #81 from sloong/master
Add direct run mode
2 parents 1985029 + bc98204 commit 8bad636

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

cmd/wsl2host/main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ import (
77
"strings"
88

99
"github.com/shayne/go-wsl2-host/cmd/wsl2host/internal"
10+
"github.com/shayne/go-wsl2-host/cmd/wsl2host/pkg/service"
1011
"golang.org/x/sys/windows/svc"
12+
"golang.org/x/sys/windows/svc/eventlog"
1113
)
1214

1315
func usage(errmsg string) {
1416
fmt.Fprintf(os.Stderr,
1517
"%s\n\n"+
1618
"usage: %s <command>\n"+
1719
" where <command> is one of\n"+
18-
" install, remove, debug, start, stop, pause or continue.\n",
20+
" install, remove, debug, start, stop, pause or continue.\n"+
21+
" run: One-time run and update.\n",
1922
errmsg, os.Args[0])
2023
os.Exit(2)
2124
}
@@ -53,6 +56,12 @@ func main() {
5356
err = internal.ControlService(svcName, svc.Pause, svc.Paused)
5457
case "continue":
5558
err = internal.ControlService(svcName, svc.Continue, svc.Running)
59+
case "run":
60+
elog, err := eventlog.Open(svcName)
61+
if err != nil {
62+
return
63+
}
64+
err = service.Run(elog)
5665
default:
5766
usage(fmt.Sprintf("invalid command %s", cmd))
5867
}

pkg/hostsapi/hostsapi.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ func GetHostIP() (string, error) {
201201
}
202202
// If system language not english, the output not "IP Address". such as in chinese it's "IP 地址".
203203
// And the output no have other such as "IP", so we can only match the "IP".
204-
ipRegex := regexp.MustCompile("IP.*:?\040*(.*)\r\n")
204+
// If need change reglar, make sure the other language is work OK.
205+
// In chinese language os, the output is:
206+
// "\r\n\xbdӿ\xda \"vEthernet (WSL)\" \xb5\xc4\xc5\xe4\xd6\xc3\r\n DHCP \xd2\xd1\xc6\xf4\xd3\xc3: \xb7\xf1\r\n IP \xb5\xd8ַ: 172.18.144.1\r\n \xd7\xd3\xcd\xf8ǰ\u05fa: 172.18.144.0/20 (\xd1\xda\xc2\xeb 255.255.240.0)\r\n InterfaceMetric: 15\r\n\r\n"
207+
ipRegex := regexp.MustCompile("IP.*:? \040*(.*)\r\n")
205208
ipString := ipRegex.FindStringSubmatch(string(out))
206209
if len(ipString) != 2 {
207210
return "", errors.New(`netsh interface ip show address "vEthernet (WSL)"`)

0 commit comments

Comments
 (0)