Skip to content

Commit

Permalink
Support Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Jul 24, 2019
1 parent 5d29bb1 commit 8b977be
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
36 changes: 29 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,41 @@ matrix:
include:
- go: 1.12.x
os: linux
env: GO111MODULE=on
before_install:
- echo $TRAVIS_GO_VERSION
- sudo pip install codecov
after_script:
- codecov
- go: master
os: linux
env: GO111MODULE=on
before_install:
- echo $TRAVIS_GO_VERSION
- sudo pip install codecov
- go: 1.12.x
os: osx
env: GO111MODULE=on
before_install:
- echo $TRAVIS_GO_VERSION
- go: master
os: osx
env: GO111MODULE=on
before_install:
- echo $TRAVIS_GO_VERSION
- go: 1.12.x
os: windows
env: GO111MODULE=on
before_install:
- echo $TRAVIS_GO_VERSION
- echo $PATH
- echo $GOPATH
- go: master
os: windows
env: GO111MODULE=on
before_install:
- echo $TRAVIS_GO_VERSION
allow_failures:
- go: master
env: GO111MODULE=on
install:
- echo $TRAVIS_GO_VERSION
- sudo pip install codecov
script:
- make ci
after_script:
- codecov
- go test ./...
14 changes: 14 additions & 0 deletions exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/rand"
"os/exec"
"runtime"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -157,6 +158,19 @@ type testcase struct {

func gentests(withSleepTest bool) []testcase {
tests := []testcase{}
if runtime.GOOS == "windows" {
r := random()
tests = append(tests, testcase{"echo", []string{"echo", r}, r, true})
r = random()
tests = append(tests, testcase{"cmd /c echo", []string{"cmd", "/c", fmt.Sprintf("echo %s", r)}, r, true})
if withSleepTest {
r = "123456"
tests = append(tests, testcase{"timeout", []string{"timeout", r, "/nobreak"}, r, false})
r = "654321"
tests = append(tests, testcase{"cmd /c timeout", []string{"cmd", "/c", fmt.Sprintf("timeout %s /nobreak && echo %s", r, r)}, r, false})
}
return tests
}
r := random()
tests = append(tests, testcase{"echo", []string{"echo", r}, r, true})
r = random()
Expand Down
30 changes: 30 additions & 0 deletions exec_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package exec

import (
"os"
"os/exec"
"strconv"
"syscall"
)

var defaultSignal = os.Interrupt

// Reference code:
// https://github.com/Songmu/timeout/blob/517fff103abc7d0e88a663609515d8bb55f6535d/timeout_windows.go
func command(name string, arg ...string) *exec.Cmd {
// #nosec
cmd := exec.Command(name, arg...)
if cmd.SysProcAttr == nil {
cmd.SysProcAttr = &syscall.SysProcAttr{}
}
cmd.SysProcAttr.CreationFlags = syscall.CREATE_UNICODE_ENVIRONMENT | 0x00000200
return cmd
}

func terminate(cmd *exec.Cmd, sig os.Signal) error {
return cmd.Process.Signal(sig)
}

func killall(cmd *exec.Cmd) error {
return exec.Command("taskkill", "/F", "/T", "/PID", strconv.Itoa(cmd.Process.Pid)).Run()
}

0 comments on commit 8b977be

Please sign in to comment.