--- a/UnixOperatingSystem.st Tue Sep 27 14:56:57 2016 +0200
+++ b/UnixOperatingSystem.st Tue Sep 27 15:03:13 2016 +0200
@@ -3785,13 +3785,14 @@
|info path|
"shortcut - use the /proc filesystem (if present).
- Here we get an absolute path to the running executable."
+ Here we get an absolute path to the running executable.
+ Notice: we cannot depend on /proc to be present (actually only is on linux)"
info := '/proc/self/exe' asFilename linkInfo.
info notNil ifTrue:[
- path := info path.
- path notEmptyOrNil ifTrue:[
- ^ path
- ].
+ path := info path.
+ path notEmptyOrNil ifTrue:[
+ ^ path
+ ].
].
"Fall back - do it the hard way"
@@ -3804,27 +3805,24 @@
!
pathOfCommand:aCommand
- "find where aCommand's executable file is;
- return its full pathName if there is such a command,
- otherwise return nil.
- This does not check if there really is an existing/executable command/program
- at the path's file - only which path would be chosen.
- To answer that question, use #canExecuteCommand:."
+ "find where aCommand's executable file would be searched for if executed by a shell.
+ Return nil if aCommand is either absolute, or relative and not executable,
+ or not executable is found along the PATH."
|path f fExt commandFilename|
commandFilename := aCommand asFilename.
commandFilename isAbsolute ifTrue:[
"/ something like "/foo/...", tried path is it
- ^ commandFilename pathName
+ ^ commandFilename pathName isExecutable
].
commandFilename isExplicitRelative ifTrue:[
"/ something like "../foo/...", tried path resolved relative to the current directory
- ^ commandFilename pathName
+ ^ commandFilename pathName isExecutable
].
(aCommand includes:$/) ifTrue:[
"/ something like "smalltalk/stx", tried path is relative to the current directory
- ^ ('./',aCommand) asFilename pathName
+ ^ ('./',aCommand) asFilename pathName isExecutable
].
"/ command is a single word, not relative and not absolute.