Installation/starting directory

Started by Maurizio, August 27, 2007, 01:17:27 AM

Previous topic - Next topic

Maurizio

Would be fine to have a NewLisp function to get the running executable directory of newlisp.exe.



The trick to query the environment variable PROGRAMFILES to get the installation directory, as shown in newlisp-edit.lsp, does not work if I install

(for example) on another disk.



Then it would be fine to update all the gs examples to use

such a new function.



Regards

Maurizio

HPW

#1
Try:
> (main-args 0)
"C:\Programme\newlisp\newlisp.exe"
Hans-Peter

Maurizio

#2
it seems to return only "newlisp"



D:Temp>newlisp

newLISP v.9.2.0 on Win32, execute 'newlisp -h' for more info.



> (main-args)

("newlisp")

> (main-args 0)

"newlisp"



Regards

Maurizio

HPW

#3
Yes, you are right for the new GUI-based editor.

Also the console does not show it when started via path variable.

Started directly with a desktop link it shows it.



??
Hans-Peter

Jeff

#4
You can check against a directory pattern for the newlisp directory using this env syntax from the docs:


(println (env "NEWLISPDIR" "/usr/bin/"))

You could write a simple function definition to iterate through a list of possibilities and evaluate to the first that is true, but that might not help if you don't know the possibilities ahead of time (such as newLisp running from a dynamically mapped drive in Windows).



In Windows, you could write a batch script that sets the current working directory as an environment variable and then read env for that variable in newLisp.  Something like:



batch file:
set WORKING_DIR=%CD%
%CD%newlisp.exe somescript.lsp


newlisp:
(set 'working_dir (env "WORKING_DIR"))
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Lutz

#5
years ago I did something like this:


(import "kernel32.exe" "GetModulePath")
(set 'path (dup "00" 256))
(GetModulePath 0 path 256)

path -> "C:\Progamm Filesnewlispnewlisp.exe"


this is the C prototype of the function:


DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize );

I don't have access to a Windows machine at the moment, and I am not sure if kernel32.exe is the right library (consult a Win32 SDK reference or ask HPW), but I remember it worked well.



Lutz

HPW

#6
Take a look here:



http://www.alh.net/newlisp/phpbb/viewtopic.php?t=141&highlight=kernel32">http://www.alh.net/newlisp/phpbb/viewto ... t=kernel32">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=141&highlight=kernel32



Or:



(import "kernel32.dll" "GetModuleFileNameA")
GetModuleFileNameA <77E90AA8>
> (set 'path (dup "00" 256))
"00000000 ..."
> (GetModuleFileNameA 0 path 256)
32
> (string path)
"C:\Programme\newlisp\newlisp.exe"
>
Hans-Peter

Maurizio

#7
Thanks, this works,

but it would be better to have a system function that works

on all supported platforms, and upgrade all the examples

to work with such a function.



Regards.

Maurizio.

Jeff

#8
I agree.  Especially in the case of programs that may be run off of a dynamically mapped drive.  Lutz, is it possible to have that set by the newlisp executable when it launches so that it would be available in env?
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Lutz

#9
yes, we can add something



Lutz

Lutz

#10
There are really two directories, one is the executable path and the other the path where the modules and util are located. Which is the path we want to have present in an environment variable?



On Windows they are the same, but not on UNIX. On UNIX almost always a newLISP program is started from a script, and then the bin path is present in (main-args).



It seems, the only thing we need then is NEWLISPDIR for the path to modules and util, which is the same for the executable on Windows.



Lutz

Jeff

#11
What would be great is a set of variables to cover all of them.  One to say where the newlisp executable is, one for the execution directory (albeit the same in Windows), and perhaps one for the global modules directory.



The initialization could check for default environmental variables that may be user set and if they do not exist, set them to the current environment.  That way, in a custom configuration (such as a custom modules directory, whatever), the user could override them.



A lot of scripting languages do that or something similar to that.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Lutz

#12
There is also the funtion 'real-path', which can be used for the current directory, right after startup with out parameters => (real-path)



Lutz

Jeff

#13
I didn't know about that one, but it sure will be helpful :)
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code