mirror of
https://github.com/xiaoqidun/wslkd.git
synced 2024-12-08 16:02:44 +08:00
45 lines
877 B
Go
45 lines
877 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"github.com/xiaoqidun/gowsl"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
"sync"
|
|
"syscall"
|
|
)
|
|
|
|
func main() {
|
|
var d string
|
|
flag.StringVar(&d, "d", "Debian", "distribution")
|
|
flag.Parse()
|
|
waitGroup := &sync.WaitGroup{}
|
|
distroList := strings.Split(d, ",")
|
|
for i := 0; i < len(distroList); i++ {
|
|
distro := strings.TrimSpace(distroList[i])
|
|
if distro == "" {
|
|
continue
|
|
}
|
|
waitGroup.Add(1)
|
|
go exec(waitGroup, distro)
|
|
}
|
|
waitGroup.Wait()
|
|
}
|
|
|
|
func exec(done *sync.WaitGroup, distro string) {
|
|
defer done.Done()
|
|
if !gowsl.Registered(distro) {
|
|
log.Printf("%v does not exist\n", distro)
|
|
return
|
|
}
|
|
cmd := gowsl.Command(distro, "/bin/bash")
|
|
cmd.Stdin = os.Stdin
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
|
if err := cmd.Run(); err != nil {
|
|
log.Printf("%v cmd run err: %v", distro, err)
|
|
}
|
|
}
|