Skip to content

Commit

Permalink
Allow reassignment of exec.Cmd Stdout and Stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Mulcahy committed Jul 17, 2015
1 parent 2e6fb17 commit 9404f81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 12 additions & 1 deletion README.md
Expand Up @@ -10,6 +10,17 @@ The choice of which browser is started is entirely client dependant.



## Variables
``` go
var Stderr io.Writer = os.Stderr
```
Stderr is the io.Writer to which executed commands write standard error.

``` go
var Stdout io.Writer = os.Stdout
```
Stdout is the io.Writer to which executed commands write standard output.


## func OpenFile
``` go
Expand Down Expand Up @@ -41,4 +52,4 @@ OpenURL opens a new browser window pointing to url.


- - -
Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)
Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)
10 changes: 8 additions & 2 deletions browser.go
Expand Up @@ -12,6 +12,12 @@ import (
"path/filepath"
)

// Stdout is the io.Writer to which executed commands write standard output.
var Stdout io.Writer = os.Stdout

// Stderr is the io.Writer to which executed commands write standard error.
var Stderr io.Writer = os.Stderr

// OpenFile opens new browser window for the file path.
func OpenFile(path string) error {
path, err := filepath.Abs(path)
Expand Down Expand Up @@ -50,7 +56,7 @@ func OpenURL(url string) error {

func runCmd(prog string, args ...string) error {
cmd := exec.Command(prog, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdout = Stdout
cmd.Stderr = Stderr
return cmd.Run()
}

0 comments on commit 9404f81

Please sign in to comment.