From d9be109b497d92461999fa723125cb753b52077f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 23 Oct 2023 22:35:23 +0000 Subject: [PATCH] Add win_main.go --- win_main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 win_main.go 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) +}