gist/win_main.go
2023-10-23 22:35:23 +00:00

43 lines
705 B
Go

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)
}