Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(871)

Side by Side Diff: go/util/command.go

Issue 1302513006: Reland of Add a library for running external commands, providing timeouts and test injection. (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Fix bug with nil io.Writer. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « go/exec/exec_test.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package util 1 package util
2 2
3 import ( 3 import (
4 » "os/exec" 4 » "go.skia.org/infra/go/exec"
5 » "strings"
6
7 » "github.com/skia-dev/glog"
8 ) 5 )
9 6
10 // DoCmd executes the given command line string; the command being 7 // DoCmd executes the given command line string; the command being
11 // run is expected to not care what its current working directory is. 8 // run is expected to not care what its current working directory is.
12 // Returns the stdout and stderr. If there is an error, the 9 // Returns the stdout and stderr.
13 // returned error will be of type ExitError, which the caller
14 // can use to find out more about what happened.
15 func DoCmd(commandLine string) (string, error) { 10 func DoCmd(commandLine string) (string, error) {
16 » glog.Infof("Command: %q\n", commandLine) 11 » return exec.RunSimple(commandLine)
17 » programAndArgs := strings.SplitN(commandLine, " ", 2)
18 » program := programAndArgs[0]
19 » args := []string{}
20 » if len(programAndArgs) > 1 {
21 » » args = strings.Split(programAndArgs[1], " ")
22 » }
23 » cmd := exec.Command(program, args...)
24 » message, err := cmd.CombinedOutput()
25 » glog.Infof("StdOut + StdErr: %s\n", string(message))
26 » if err != nil {
27 » » glog.Errorf("Exit status: %s\n", err)
28 » » return string(message), err
29 » }
30 » return string(message), nil
31 } 12 }
OLDNEW
« no previous file with comments | « go/exec/exec_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698