You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/common/platform/ctlcmd/ctlcmd.go

45 lines
929 B

package ctlcmd
import (
"io"
"os"
"os/exec"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/platform"
)
6 years ago
//go:generate errorgen
func Run(args []string, input io.Reader) (buf.MultiBuffer, error) {
v2ctl := platform.GetToolLocation("v2ctl")
if _, err := os.Stat(v2ctl); err != nil {
return nil, newError("v2ctl doesn't exist").Base(err)
}
var errBuffer buf.MultiBufferContainer
var outBuffer buf.MultiBufferContainer
cmd := exec.Command(v2ctl, args...)
7 years ago
cmd.Stderr = &errBuffer
cmd.Stdout = &outBuffer
cmd.SysProcAttr = getSysProcAttr()
if input != nil {
cmd.Stdin = input
}
if err := cmd.Start(); err != nil {
return nil, newError("failed to start v2ctl").Base(err)
}
7 years ago
if err := cmd.Wait(); err != nil {
msg := "failed to execute v2ctl"
if errBuffer.Len() > 0 {
msg += ": " + errBuffer.MultiBuffer.String()
}
7 years ago
return nil, newError(msg).Base(err)
}
return outBuffer.MultiBuffer, nil
}