[Pharo-project] [ VM ]Smalltalk getSystemAttribute:
David T. Lewis
lewis at mail.msen.com
Tue Jan 3 08:07:06 EST 2012
On Tue, Jan 03, 2012 at 11:54:18PM +1100, Ben Coman wrote:
> Esteban Lorenzano wrote:
> >El 02/01/2012, a las 4:39p.m., David T. Lewis escribi?:
> >>>Real problem then is:
> >>>we don't have a way to get the executable name
> >>>getSystemAttribute: comment is wrong :)
> >>On a unix VM, it answers the full path to the executable, which is
> >>in agreement with the comment. For example:
> >> Smalltalk getSystemAttribute: 0 ==>
> >> '/usr/local/lib/squeak/4.7.18-2505/squeakvm'
> >>Maybe is is more complicated for Mac, but wasn't there some discussion
> >>about it on vm-dev a while back?
> >I don't remember :)
> >so, how can we solve this? of course, it is not a problem to make
> >getSystemAttribute: 0 answer argv, but that's not the expected
> >behavior... we can be making a mistake, because it should answer vm path,
> >no vm fullName.
> >I can add a 10XX number to answer vm full name, but that will lead to
> >consistency problems inside the image...
> >I really don't know how to proceed :(
> I am not sure of the semantics within Smalltalk, but within both Windows
> & Linux "full path" includes the filename. Examples...
> Linux `which` command 
> "...printing the full path when used from a script"
> > echo `which q2`
> Windows Path.GetFullPath method 
> "Returns the absolute path for the specified path string."
> // GetFullPath('mydir') returns 'C:\temp\Demo\mydir'
> // GetFullPath('myfile.ext') returns 'C:\temp\Demo\myfile.ext'
> From browsing around it does seem harder on OSX to determine the path
> to the current executable [3,4,5,6] but I'm not qualified to comment.
In the unix VM (see platforms/unix/vm/sqUnixMain.c), it is done using
argv and the realpath() function. In other words, take the program
name from the command line, and pass it though realpath() to resolve
symbolic links. I don't know if this approach works on OS X though.
> cheers, Ben
>  http://linux.die.net/man/1/which
>  http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath.aspx
More information about the Pharo-dev