Skip to content

os/exec: document subtleties around Cmd.Dir, PWD, os.Getwd and C's getcwd #68000

@adonovan

Description

@adonovan

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 the PWD variable implicitly in order to make os.Getwd, and similar functions such as GNU C's get_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).

Metadata

Metadata

Assignees

Labels

DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.gabywins

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions