os/exec: document subtleties around Cmd.Dir, PWD, os.Getwd and C's getcwd #68000
Labels
Documentation
Issues describing a change to documentation.
gabywins
NeedsFix
The path to resolution is known, but the work has not been done.
The interaction of exec.Cmd and os.Getwd is rather subtle: the working directory of a POSIX process is represented by a file descriptor, not a string, so C's getcwd will always return a real (symlink-free) path. By contrast, Go's os.Getwd will return the value of $PWD if it is an alias for the real path. (It does not do this for ancestors or other directories: it won't return $PWD/foo if that is an alias for getcwd, for example.)
exec.Cmd
sets thePWD
variable implicitly in order to makeos.Getwd
, and similar functions such as GNU C'sget_current_dir_name
, work this way--but it only does so in certain circumstances.We should document the subtleties of this issue so that users of os/exec and os.Getwd don't get confused (as I did in #67757).
The text was updated successfully, but these errors were encountered: