aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec/exec.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2019-03-20 14:09:51 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2019-03-21 13:19:55 +0000
commit6249ea2f39958764b88ab1b03cd55cf99dae6bbd (patch)
treec11589246f59d72ea942f95ae4944f5613f415aa /src/os/exec/exec.go
parenteb00167e27ba3525d26bbe9286c82090da782587 (diff)
downloadgo-6249ea2f39958764b88ab1b03cd55cf99dae6bbd.tar.gz
go-6249ea2f39958764b88ab1b03cd55cf99dae6bbd.zip
os/exec: add Cmd.String
The initial implementation is intentionally simple. Let's see how far it gets us. Fixes #30638 Change-Id: I240afae2b401744ab2ff2a69952c4eb0fd3feb56 Reviewed-on: https://go-review.googlesource.com/c/go/+/168518 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/os/exec/exec.go')
-rw-r--r--src/os/exec/exec.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go
index 424b49cf06..d481cf7798 100644
--- a/src/os/exec/exec.go
+++ b/src/os/exec/exec.go
@@ -190,6 +190,25 @@ func CommandContext(ctx context.Context, name string, arg ...string) *Cmd {
return cmd
}
+// String returns a human-readable description of c.
+// It is intended only for debugging.
+// In particular, it is not suitable for use as input to a shell.
+// The output of String may vary across Go releases.
+func (c *Cmd) String() string {
+ if c.lookPathErr != nil {
+ // failed to resolve path; report the original requested path (plus args)
+ return strings.Join(c.Args, " ")
+ }
+ // report the exact executable path (plus args)
+ b := new(strings.Builder)
+ b.WriteString(c.Path)
+ for _, a := range c.Args[1:] {
+ b.WriteByte(' ')
+ b.WriteString(a)
+ }
+ return b.String()
+}
+
// interfaceEqual protects against panics from doing equality tests on
// two interfaces with non-comparable underlying types.
func interfaceEqual(a, b interface{}) bool {