2016-10-24 00:44:56 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2017-10-15 09:32:59 +00:00
|
|
|
"fmt"
|
2016-10-24 00:44:56 +00:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
2017-01-07 16:30:31 +00:00
|
|
|
"syscall"
|
2016-10-24 00:44:56 +00:00
|
|
|
)
|
|
|
|
|
2017-09-28 14:05:02 +00:00
|
|
|
// ExecCommand executes the given command with cmd
|
2016-10-24 00:44:56 +00:00
|
|
|
func ExecCommand(command string) *exec.Cmd {
|
2017-09-28 14:05:02 +00:00
|
|
|
return ExecCommandWith("cmd", command)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecCommandWith executes the given command with cmd. _shell parameter is
|
|
|
|
// ignored on Windows.
|
|
|
|
func ExecCommandWith(_shell string, command string) *exec.Cmd {
|
2017-10-02 15:36:19 +00:00
|
|
|
cmd := exec.Command("cmd")
|
|
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
2017-10-15 09:32:59 +00:00
|
|
|
HideWindow: false,
|
|
|
|
CmdLine: fmt.Sprintf(` /s /c "%s"`, command),
|
|
|
|
CreationFlags: 0,
|
2017-10-02 15:36:19 +00:00
|
|
|
}
|
|
|
|
return cmd
|
2016-11-06 17:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsWindows returns true on Windows
|
|
|
|
func IsWindows() bool {
|
|
|
|
return true
|
2016-10-24 00:44:56 +00:00
|
|
|
}
|
2017-01-07 16:30:31 +00:00
|
|
|
|
|
|
|
// SetNonBlock executes syscall.SetNonblock on file descriptor
|
|
|
|
func SetNonblock(file *os.File, nonblock bool) {
|
|
|
|
syscall.SetNonblock(syscall.Handle(file.Fd()), nonblock)
|
|
|
|
}
|
2017-05-24 16:36:59 +00:00
|
|
|
|
|
|
|
// Read executes syscall.Read on file descriptor
|
|
|
|
func Read(fd int, b []byte) (int, error) {
|
|
|
|
return syscall.Read(syscall.Handle(fd), b)
|
|
|
|
}
|