-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.go
More file actions
34 lines (27 loc) · 773 Bytes
/
Copy pathrun.go
File metadata and controls
34 lines (27 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package mx
import (
"bytes"
"io"
"log"
"os"
"github.com/magefile/mage/sh"
)
// ExecSilent executes commands with the UNIX / Go idiom of silencing output unless of an error.
func ExecSilent(env map[string]string, program string, args ...string) error {
var stdout bytes.Buffer
var stderr bytes.Buffer
_, err := sh.Exec(env, &stdout, &stderr, program, args...)
if err != nil {
if _, err2 := io.Copy(os.Stdout, &stdout); err2 != nil {
log.Println(err2)
}
if _, err2 := io.Copy(os.Stderr, &stderr); err2 != nil {
log.Println(err2)
}
}
return err
}
// RunVSilent executes commands with the UNIX / Go idiom of silencing output unless of an error.
func RunVSilent(program string, args ...string) error {
return ExecSilent(nil, program, args...)
}