UnixOperatingSystem.st
changeset 20456 b87283a19b7f
parent 20455 893fe6053faf
child 20460 4831c0d89182
equal deleted inserted replaced
20455:893fe6053faf 20456:b87283a19b7f
  3783      but may be different for standAlone apps (or winstx.exe)."
  3783      but may be different for standAlone apps (or winstx.exe)."
  3784 
  3784 
  3785     |info path|
  3785     |info path|
  3786 
  3786 
  3787     "shortcut - use the /proc filesystem (if present).
  3787     "shortcut - use the /proc filesystem (if present).
  3788      Here we get an absolute path to the running executable."
  3788      Here we get an absolute path to the running executable.
       
  3789      Notice: we cannot depend on /proc to be present (actually only is on linux)"
  3789     info := '/proc/self/exe' asFilename linkInfo.
  3790     info := '/proc/self/exe' asFilename linkInfo.
  3790     info notNil ifTrue:[
  3791     info notNil ifTrue:[
  3791 	path := info path.
  3792         path := info path.
  3792 	path notEmptyOrNil ifTrue:[
  3793         path notEmptyOrNil ifTrue:[
  3793 	    ^ path
  3794             ^ path
  3794 	].
  3795         ].
  3795      ].
  3796      ].
  3796 
  3797 
  3797     "Fall back - do it the hard way"
  3798     "Fall back - do it the hard way"
  3798 
  3799 
  3799     ^ super nameOfSTXExecutable
  3800     ^ super nameOfSTXExecutable
  3802      OperatingSystem nameOfSTXExecutable
  3803      OperatingSystem nameOfSTXExecutable
  3803     "
  3804     "
  3804 !
  3805 !
  3805 
  3806 
  3806 pathOfCommand:aCommand
  3807 pathOfCommand:aCommand
  3807     "find where aCommand's executable file is;
  3808     "find where aCommand's executable file would be searched for if executed by a shell.
  3808      return its full pathName if there is such a command, 
  3809      Return nil if aCommand is either absolute, or relative and not executable,
  3809      otherwise return nil.
  3810      or not executable is found along the PATH."
  3810      This does not check if there really is an existing/executable command/program 
       
  3811      at the path's file - only which path would be chosen.
       
  3812      To answer that question, use #canExecuteCommand:."
       
  3813 
  3811 
  3814     |path f fExt commandFilename|
  3812     |path f fExt commandFilename|
  3815 
  3813 
  3816     commandFilename := aCommand asFilename.
  3814     commandFilename := aCommand asFilename.
  3817     commandFilename isAbsolute ifTrue:[
  3815     commandFilename isAbsolute ifTrue:[
  3818         "/ something like "/foo/...", tried path is it
  3816         "/ something like "/foo/...", tried path is it
  3819         ^ commandFilename pathName
  3817         ^ commandFilename pathName isExecutable
  3820     ].
  3818     ].
  3821     commandFilename isExplicitRelative ifTrue:[
  3819     commandFilename isExplicitRelative ifTrue:[
  3822         "/ something like "../foo/...", tried path resolved relative to the current directory
  3820         "/ something like "../foo/...", tried path resolved relative to the current directory
  3823          ^ commandFilename pathName
  3821          ^ commandFilename pathName isExecutable
  3824     ].
  3822     ].
  3825     (aCommand includes:$/) ifTrue:[
  3823     (aCommand includes:$/) ifTrue:[
  3826         "/ something like "smalltalk/stx", tried path is relative to the current directory
  3824         "/ something like "smalltalk/stx", tried path is relative to the current directory
  3827         ^ ('./',aCommand) asFilename pathName
  3825         ^ ('./',aCommand) asFilename pathName isExecutable
  3828     ].
  3826     ].
  3829 
  3827 
  3830     "/ command is a single word, not relative and not absolute.
  3828     "/ command is a single word, not relative and not absolute.
  3831     "/ search along PATH environment variable to see what a shoell would do.
  3829     "/ search along PATH environment variable to see what a shoell would do.
  3832     path := self getEnvironment:'PATH'.
  3830     path := self getEnvironment:'PATH'.