-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Process.executable_path? to access current executable file path #3376
Add Process.executable_path? to access current executable file path #3376
Conversation
bda1da4
to
4ed03fc
Compare
on linux you return /proc/self/exe, this is symlink, i think need to readlink for it. because some times need real path, dir or exe. |
@kostya I don't follow symlinks by default for all destinations. This is stated in the documentation. For every platform, the reported executable file may be a symlink. I chose to because there is no need for that to open the current executable (eg: to read the DWARF sections); but I have no problem changing this to always call |
I think that might be a bit inconsistent and will force users that want to use There is also chances for newcomers to perform One last point is that you lookup for that executable name in |
I didn't look at the code yet, but I would just name it |
@luislavena good points. I'll change that. |
4ed03fc
to
83a1d59
Compare
@asterite I just pushed the changes. Process -> File, no more
I only lookup into PATH only after checking that the name didn't contain any file separator ('' or |
I like |
👍 from me. I'd also use |
PATH_DELIMITER = {% if flag?(:windows) %} ';' {% else %} ':' {% end %} | ||
|
||
# :nodoc: | ||
INITIAL_PATH = ENV["PATH"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is PATH
always present? Maybe, just in case, we can use ENV["PATH"]?
(same below) and return nil
if it's not set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good catch!
I'll fix that today. |
The implementation is platform specific, and falls back to resolving PROGRAM_NAME (`argv[0]`) relatively to the initial PWD, then searching the executable name within the initial PATH. Based on work by @kostya closes crystal-lang#1812
83a1d59
to
ab59fc9
Compare
@asterite done. |
@ysbaddaden Thank you!!! ❤️ |
The implementation is platform specific, and falls back to resolving PROGRAM_NAME (
argv[0]
) relatively to the initial PWD, then searching the executable name within the initial PATH.Use cases:
Based on work by @kostya, and whereami.
closes #1812