Add win_main.go
This commit is contained in:
parent
cec8dce72e
commit
d9be109b49
42
win_main.go
Normal file
42
win_main.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user