Skip to content

Commit 9404f81

Browse files
author
Brandon Mulcahy
committed
Allow reassignment of exec.Cmd Stdout and Stderr
1 parent 2e6fb17 commit 9404f81

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ The choice of which browser is started is entirely client dependant.
1010

1111

1212

13+
## Variables
14+
``` go
15+
var Stderr io.Writer = os.Stderr
16+
```
17+
Stderr is the io.Writer to which executed commands write standard error.
18+
19+
``` go
20+
var Stdout io.Writer = os.Stdout
21+
```
22+
Stdout is the io.Writer to which executed commands write standard output.
23+
1324

1425
## func OpenFile
1526
``` go
@@ -41,4 +52,4 @@ OpenURL opens a new browser window pointing to url.
4152

4253

4354
- - -
44-
Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)
55+
Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)

browser.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import (
1212
"path/filepath"
1313
)
1414

15+
// Stdout is the io.Writer to which executed commands write standard output.
16+
var Stdout io.Writer = os.Stdout
17+
18+
// Stderr is the io.Writer to which executed commands write standard error.
19+
var Stderr io.Writer = os.Stderr
20+
1521
// OpenFile opens new browser window for the file path.
1622
func OpenFile(path string) error {
1723
path, err := filepath.Abs(path)
@@ -50,7 +56,7 @@ func OpenURL(url string) error {
5056

5157
func runCmd(prog string, args ...string) error {
5258
cmd := exec.Command(prog, args...)
53-
cmd.Stdout = os.Stdout
54-
cmd.Stderr = os.Stderr
59+
cmd.Stdout = Stdout
60+
cmd.Stderr = Stderr
5561
return cmd.Run()
5662
}

0 commit comments

Comments
 (0)