diff --git a/win_main.go b/win_main.go new file mode 100644 index 0000000..f25fa8e --- /dev/null +++ b/win_main.go @@ -0,0 +1,42 @@ +package main + +import ( + "bytes" + "context" + "fmt" + "io" + "os/exec" + "strings" +) + +func main() { + ctx := context.Background() + buf := bytes.NewBuffer([]byte{}) + + script := "echo ja; Get-Location" + + cmd := exec.CommandContext(ctx, "powershell") + + out, _ := cmd.StdoutPipe() + cmd.Stderr = cmd.Stdout + in, _ := cmd.StdinPipe() + + go func() { + io.Copy(in, strings.NewReader(script)) + in.Close() + }() + fmt.Println("####### START #######") + if err := cmd.Start(); err != nil { + fmt.Printf("Start err: %v\n\n", err) + } + + go io.Copy(buf, out) + + fmt.Println("####### WAIT #######") + if err := cmd.Wait(); err != nil { + fmt.Printf("Wait err: %v\n\n", err) + } + fmt.Println("####### END #######") + + fmt.Print(buf) +}