mirror of
https://github.com/Baipyrus/ProxySwitcher.git
synced 2024-12-26 04:31:45 +00:00
preparing a single command process to execute in
This commit is contained in:
parent
6037f4b34f
commit
bb304b0bf7
@ -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
34
util/util.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user