MCPcopy Create free account
hub / github.com/google/gapid / ExampleCapture

Function ExampleCapture

core/os/shell/command_example_test.go:60–78  ·  view source on GitHub ↗

This example shows how to run a command and capture it's output.

()

Source from the content-addressed store, hash-verified

58
59// This example shows how to run a command and capture it's output.
60func ExampleCapture() {
61 ctx := newCtx()
62 stdout := &bytes.Buffer{}
63 stderr := &bytes.Buffer{}
64 echo := shell.Command("echo").Verbose().Capture(stdout, stderr)
65 echo.With("First echo").Run(ctx)
66 echo.With("Second echo").Run(ctx)
67 log.I(ctx, "<{<%s}>", stdout.String())
68 log.W(ctx, "<!{<%s}!>", stderr.String())
69 // Output:
70 //I: [Example] Exec: echo "First echo"
71 //I: [Example] <echo> First echo
72 //I: [Example] Exec: echo "Second echo"
73 //I: [Example] <echo> Second echo
74 //I: [Example] <{<First echo
75 //Second echo
76 //}>
77 //W: [Example] <!{<}!>
78}

Callers

nothing calls this directly

Calls 9

VerboseMethod · 0.80
IMethod · 0.80
newCtxFunction · 0.70
CaptureMethod · 0.65
CommandMethod · 0.65
RunMethod · 0.65
StringMethod · 0.65
WithMethod · 0.45
WMethod · 0.45

Tested by

no test coverage detected