Skip to content

Commit

Permalink
more fixes on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mgutz committed Mar 3, 2015
1 parent 0d1672c commit d0c2b90
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
5 changes: 4 additions & 1 deletion cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package godo

import (
"bytes"
"fmt"
"os"
"os/exec"

Expand Down Expand Up @@ -82,15 +83,17 @@ func (gcmd *command) runAsync() (err error) {

// kills previously spawned process (if exists)
killSpawned(id)
waitExit = true
waitgroup.Add(1)
waitExit = true
go func() {
err = cmd.Start()
if err != nil {
fmt.Println(err.Error())
return
}
spawnedProcesses[id] = cmd.Process
c := make(chan error, 1)

c <- cmd.Wait()
_ = <-c
waitgroup.Done()
Expand Down
2 changes: 1 addition & 1 deletion cmd/example/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import (
)

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
fmt.Fprintf(w, "Hi there, I hate %s!", r.URL.Path[1:])
}
3 changes: 1 addition & 2 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"os"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -68,7 +67,7 @@ func Start(commandstr string, options ...interface{}) error {
if err != nil {
return err
}
executable = path.Base(dir)
executable = filepath.Base(dir)
}

cmd := &command{
Expand Down
34 changes: 26 additions & 8 deletions project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,39 +231,57 @@ func TestBash(t *testing.T) {

func TestLegacyIn(t *testing.T) {

//// Bash
var cat = "cat"
if isWindows {
cat = "cmd /c type"
}
//// Run

// in V2 BashOutput accepts an options map
out, err := BashOutput("cat foo.txt", M{"$in": "test"})

out, err := RunOutput(cat+" foo.txt", M{"$in": "test"})
assert.NoError(t, err)
assert.Equal(t, "asdf", str.Clean(out))

// need to support V1 though
out, err = BashOutput("cat foo.txt", In{"test"})
out, err = RunOutput(cat+" foo.txt", In{"test"})
assert.NoError(t, err)
assert.Equal(t, "asdf", str.Clean(out))

//// Run
if isWindows {
return
}

//// Bash

// in V2 BashOutput accepts an options map
out, err = RunOutput("cat foo.txt", M{"$in": "test"})
out, err = BashOutput("cat foo.txt", M{"$in": "test"})
assert.NoError(t, err)
assert.Equal(t, "asdf", str.Clean(out))

// need to support V1 though
out, err = RunOutput("cat foo.txt", In{"test"})
out, err = BashOutput("cat foo.txt", In{"test"})
assert.NoError(t, err)
assert.Equal(t, "asdf", str.Clean(out))
}

func TestTemplatedCommands(t *testing.T) {
echo := "echo"
if isWindows {
echo = "cmd /c echo"

}
// in V2 BashOutput accepts an options map
out, err := BashOutput("echo {{.name}}", M{"name": "oy"})
out, err := RunOutput(echo+" {{.name}}", M{"name": "oy"})
assert.NoError(t, err)
assert.Equal(t, "oy", str.Clean(out))

if isWindows {
return
}

// in V2 BashOutput accepts an options map
out, err = RunOutput("echo {{.name}}", M{"name": "oy"})
out, err = BashOutput("echo {{.name}}", M{"name": "oy"})
assert.NoError(t, err)
assert.Equal(t, "oy", str.Clean(out))
}
Expand Down

0 comments on commit d0c2b90

Please sign in to comment.