Skip to content
Snippets Groups Projects
util_unix.go 655 B
Newer Older
// +build !windows

package util

import (
	"os"
	"os/exec"
Junegunn Choi's avatar
Junegunn Choi committed
	"syscall"
)

// ExecCommand executes the given command with $SHELL
func ExecCommand(command string) *exec.Cmd {
	shell := os.Getenv("SHELL")
	if len(shell) == 0 {
		shell = "sh"
	}
	return exec.Command(shell, "-c", command)
}

// IsWindows returns true on Windows
func IsWindows() bool {
	return false
}
Junegunn Choi's avatar
Junegunn Choi committed

// SetNonBlock executes syscall.SetNonblock on file descriptor
func SetNonblock(file *os.File, nonblock bool) {
	syscall.SetNonblock(int(file.Fd()), nonblock)
}

// Read executes syscall.Read on file descriptor
func Read(fd int, b []byte) (int, error) {
	return syscall.Read(int(fd), b)
}