diff options
Diffstat (limited to 'src/os/exec/example_test.go')
-rw-r--r-- | src/os/exec/example_test.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/os/exec/example_test.go b/src/os/exec/example_test.go index a66890be69..bb166ceaf4 100644 --- a/src/os/exec/example_test.go +++ b/src/os/exec/example_test.go @@ -144,6 +144,21 @@ func ExampleCmd_CombinedOutput() { fmt.Printf("%s\n", stdoutStderr) } +func ExampleCmd_Environ() { + cmd := exec.Command("pwd") + + // Set Dir before calling cmd.Environ so that it will include an + // updated PWD variable (on platforms where that is used). + cmd.Dir = ".." + cmd.Env = append(cmd.Environ(), "POSIXLY_CORRECT=1") + + out, err := cmd.Output() + if err != nil { + log.Fatal(err) + } + fmt.Printf("%s\n", out) +} + func ExampleCommandContext() { ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer cancel() |