preparing a single command process to execute in

This commit is contained in:
Baipyrus 2024-08-31 18:26:45 +02:00
parent 6037f4b34f
commit bb304b0bf7
2 changed files with 39 additions and 0 deletions

View File

@ -19,3 +19,8 @@ type Variant struct {
Type Type `json:"type,omitempty"`
Equator string `json:"equator,omitempty"`
}
type Command struct {
Name string
Arguments []string
}

34
util/util.go Normal file
View File

@ -0,0 +1,34 @@
package util
import (
"bytes"
"io"
"os/exec"
)
func ReadyCmd() (*io.WriteCloser, func() error, error) {
cmd := exec.Command("powershell", "-NoLogo", "-NoProfile", "-Command", "-")
var stdout bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stdout
stdin, err := cmd.StdinPipe()
if err != nil {
return nil, nil, err
}
if err := cmd.Start(); err != nil {
return nil, nil, err
}
return &stdin, func() error {
stdin.Close()
if err := cmd.Wait(); err != nil {
return err
}
return nil
}, nil
}