2016-10-24 00:44:56 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2017-01-07 16:30:31 +00:00
|
|
|
"syscall"
|
2016-11-06 17:15:34 +00:00
|
|
|
|
|
|
|
"github.com/junegunn/go-shellwords"
|
2016-10-24 00:44:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ExecCommand executes the given command with $SHELL
|
|
|
|
func ExecCommand(command string) *exec.Cmd {
|
|
|
|
shell := os.Getenv("SHELL")
|
|
|
|
if len(shell) == 0 {
|
|
|
|
shell = "cmd"
|
|
|
|
}
|
2016-11-06 17:15:34 +00:00
|
|
|
args, _ := shellwords.Parse(command)
|
|
|
|
allArgs := make([]string, len(args)+1)
|
|
|
|
allArgs[0] = "/c"
|
|
|
|
copy(allArgs[1:], args)
|
|
|
|
return exec.Command(shell, allArgs...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|