Skip to content

os: introduce Executable to return the path of the current executable #12773

Closed
@minux

Description

@minux

This proposes to introduce a new API in package os that addresses #4057.

package os

// Executable returns the path name for the executable that starts the
// current process. The result is the path is used to start the the current
// process, but there is no guarantee that the path is still pointing to
// the correct executable.
//
// The main use case is finding resources located relative to an executable.
//
// Not all OS support this, but all popular ones do.
func Executable() (string, error)

This API has been proposed before, but rejected on the ground that it's impossible
to formally define its semantic, but that's because the old proposal says the result
can be used to re-exec the current process. If we relax the condition that it returns
the original path that starts the current process, its semantic is fully defined on
all supported platforms. Not being to re-exec the current process is not a big issue
as the primary use case is to find relatively positioned resource files (i.e. OS X app
bundles.)

The implementation is already available in https://golang.org/cl/6736069, we just
have to brought it up to date.

I'd like to thank @kardianos for the suggestion of the new semantic.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions