Updates #16360
Change-Id: I0e0afe7a89f2ebcb3e5bbc345f77a605d3afc398
Reviewed-on: https://go-review.googlesource.com/30103
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
import (
"bytes"
+ "context"
"encoding/json"
"fmt"
"io"
"log"
"os/exec"
"strings"
+ "time"
)
func ExampleLookPath() {
}
fmt.Printf("%s\n", stdoutStderr)
}
+
+func ExampleCommandContext() {
+ ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
+ defer cancel()
+
+ if err := exec.CommandContext(ctx, "sleep", "5").Run(); err != nil {
+ // This will fail after 100 milliseconds. The 5 second sleep
+ // will be interrupted.
+ }
+}