diff options
| author | Bryan C. Mills <bcmills@google.com> | 2022-04-20 17:07:14 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-04-21 17:37:05 +0000 |
| commit | b34838913da606087b0f3141891f7d0fb2254eef (patch) | |
| tree | e82ffa5fd4b077814e4d2fe55ca399325f6b81ff /src/os/exec/example_test.go | |
| parent | 115852077f45141b293727558e61c0804661d328 (diff) | |
| download | go-b34838913da606087b0f3141891f7d0fb2254eef.tar.xz | |
os/exec: set PWD implicitly if Dir is non-empty and Env is nil
Fixes #50599.
Change-Id: I4e5dbb3972cdf21ede049567bfb98f2c992c5849
Reviewed-on: https://go-review.googlesource.com/c/go/+/401340
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
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() |
