Re: [eclipse-clp-users] Finding the ECLiPSE startup directory

From: Paulo Moura <pmoura_at_...16...>
Date: Mon, 16 Mar 2009 17:51:45 +0000
On 2009/03/16, at 17:26, Kish Shen wrote:

> Paulo Moura wrote:
>> On 2009/03/16, at 14:05, Paulo Moura wrote:
>>> I'm looking for a cross-platform solution to find the startup
>>> directory when running ECLiPSe. On POSIX systems is easy as the
>>> environment variable PWD is usually defined so the solution is  
>>> simply
>>> to use getenv/2. This, of course, doesn't work on Windows. Is there
>>> any way to find the startup directory that would work across all
>>> operating-systems supported by ECLiPSe?
>> Please note that using getcwd/1  doesn't work as this built-in   
>> predicate returns the directory of the file being compiled, not  
>> the  directory from which ECLiPSE was started.
>> Paulo
>>
> Hi Paulo,
>
> getcwd/1 `doesn't work' if you run it within a directive in a file  
> that is compiled. This is because the current directory is changed  
> while you are compiling files. [this is to enable any relative  
> pathnames within your compiled files to behave in the expected way,  
> relative to the file]

Understood. I find this behavior reasonable.

> If you are running ECLiPSe interactively, or running ECLiPSe in  
> batch mode. then issuing getcwd/1 (via -e command line option if you  
> are running batch eclipse) will return the current working  
> directory, which is the startup directory unless you have explicitly  
> changed the directory.
>
> I am not quite sure how useful it is to know the startup directory  
> when you start ECLiPSe on Windows from the start menu -- in this  
> case, I think the initial current working directory is fixed by  
> Windows (My\ Document in the Vista machine I tried). Normally, if  
> you are running some application, you should change the directory to  
> the one you are interested in (e.g. where you application is) when  
> you start ECLiPSe (and if you have embedded ECLiPSe in some external  
> application, then its working directory is that of the external  
> application).


Allow me to briefly describe the problem I'm trying to solve. When  
starting up Logtalk (using ECLiPSE as the back-end Prolog compiler),  
the startup (Prolog) script looks into the current directory for a  
settings file. If not found, it looks for the file in the Logtalk user  
folder. If still not found, the default settings in the back-end  
Prolog compiler configuration file are used. This allows easy, per- 
project customizations of Logtalk settings. It also makes it more  
simple to update Logtalk as there is no longer a need to reapply  
configuration file customizations. For POSIX systems this is easy:

:- (	atom_string('$PWD/settings.pl', String),  
canonical_path_name(String, File), exists(File) ->
		compile('$PWD/settings.pl')
	;	atom_string('$LOGTALKUSER/settings.pl', String),  
canonical_path_name(String, File), exists(File) ->
		compile('$LOGTALKUSER/settings.pl')
	;	true
	).

I would like to also have a similar solution for Windows. Note that  
you can easily create a shortcut for the Windows Start Menu menu item  
that runs ECLiPSe and configure this shortcut to assume as the current  
directory the directory containing the shortcut.

Cheers,

Paulo


-----------------------------------------------------------------
Paulo Jorge Lopes de Moura, PhD
Assistant Professor
Dep. of Computer Science, University of Beira Interior
6201-001 Covilhã, Portugal

Office 4.3  Ext. 3257
Phone: +351 275319891 Fax: +351 275319899
Email: <mailto:pmoura_at_...16...>

Home page: <http://www.di.ubi.pt/~pmoura>
Research:  <http://logtalk.org/>
-----------------------------------------------------------------
Received on Mon Mar 16 2009 - 17:52:06 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 22 2024 - 18:13:20 CET