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

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

Issue 1300273002: 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 squashWriters for struct arguments. 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') | go/util/util.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 package util
2
3 import (
4 "os/exec"
5 "strings"
6
7 "github.com/skia-dev/glog"
8 )
9
10 // DoCmd executes the given command line string; the command being
11 // run is expected to not care what its current working directory is.
12 // Returns the stdout and stderr. If there is an error, the
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) {
16 glog.Infof("Command: %q\n", 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 }
OLDNEW
« no previous file with comments | « go/exec/exec_test.go ('k') | go/util/util.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698