We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b9fd510 commit a9b4953Copy full SHA for a9b4953
src/os/exec/example_test.go
@@ -6,13 +6,15 @@ package exec_test
6
7
import (
8
"bytes"
9
+ "context"
10
"encoding/json"
11
"fmt"
12
"io"
13
"io/ioutil"
14
"log"
15
"os/exec"
16
"strings"
17
+ "time"
18
)
19
20
func ExampleLookPath() {
@@ -123,3 +125,13 @@ func ExampleCmd_CombinedOutput() {
123
125
}
124
126
fmt.Printf("%s\n", stdoutStderr)
127
128
+
129
+func ExampleCommandContext() {
130
+ ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
131
+ defer cancel()
132
133
+ if err := exec.CommandContext(ctx, "sleep", "5").Run(); err != nil {
134
+ // This will fail after 100 milliseconds. The 5 second sleep
135
+ // will be interrupted.
136
+ }
137
+}
0 commit comments