Add win_main.go

This commit is contained in:
6543 2023-10-23 22:35:23 +00:00
parent cec8dce72e
commit d9be109b49

42
win_main.go Normal file
View File

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