Skip to content

Commit

Permalink
Merge pull request #81 from sloong/master
Browse files Browse the repository at this point in the history
Add direct run mode
  • Loading branch information
wcb33 authored Jan 12, 2023
2 parents 1985029 + bc98204 commit 8bad636
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion cmd/wsl2host/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import (
"strings"

"github.com/shayne/go-wsl2-host/cmd/wsl2host/internal"
"github.com/shayne/go-wsl2-host/cmd/wsl2host/pkg/service"
"golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/eventlog"
)

func usage(errmsg string) {
fmt.Fprintf(os.Stderr,
"%s\n\n"+
"usage: %s <command>\n"+
" where <command> is one of\n"+
" install, remove, debug, start, stop, pause or continue.\n",
" install, remove, debug, start, stop, pause or continue.\n"+
" run: One-time run and update.\n",
errmsg, os.Args[0])
os.Exit(2)
}
Expand Down Expand Up @@ -53,6 +56,12 @@ func main() {
err = internal.ControlService(svcName, svc.Pause, svc.Paused)
case "continue":
err = internal.ControlService(svcName, svc.Continue, svc.Running)
case "run":
elog, err := eventlog.Open(svcName)
if err != nil {
return
}
err = service.Run(elog)
default:
usage(fmt.Sprintf("invalid command %s", cmd))
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/hostsapi/hostsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ func GetHostIP() (string, error) {
}
// If system language not english, the output not "IP Address". such as in chinese it's "IP 地址".
// And the output no have other such as "IP", so we can only match the "IP".
ipRegex := regexp.MustCompile("IP.*:?\040*(.*)\r\n")
// If need change reglar, make sure the other language is work OK.
// In chinese language os, the output is:
// "\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"
ipRegex := regexp.MustCompile("IP.*:? \040*(.*)\r\n")
ipString := ipRegex.FindStringSubmatch(string(out))
if len(ipString) != 2 {
return "", errors.New(`netsh interface ip show address "vEthernet (WSL)"`)
Expand Down

0 comments on commit 8bad636

Please sign in to comment.