[GRASS-dev] Windows-style Pathnames

Paul Kelly paul-grass at stjohnspoint.co.uk
Tue Nov 7 16:28:48 EST 2006

On Fri, 3 Nov 2006, Glynn Clements wrote:

> Currently, a lot of GRASS assumes that scripts can be treated as
> executables, as they are on Unix. I.e. you can call system("foo") and
> it doesn't matter whether foo is a compiled executable or a script.
> You can do this on Windows, but the file needs to have an extension to
> indicate how it is run (Unix detects this from the file's header, e.g.
> #! for scripts). The PATHEXT environment variable contains a
> semicolon-separated list of extensions which are treated as indicating
> an executable. On my system, it is set to:
> If you execute a "command" without a directory or extension, Windows
> will consider files with any of those extensions when trying to
> resolve the command name to an executable, effectively doing:
> 	for dir in $PATH ; do
> 	  for ext in $PATHEXT ; do
> 	    if [ -f $dir/$cmd$ext] ; then
> 	      exec $dir/$cmd$ext
> 	    fi
> 	  done
> 	done
> AFAICT, the "interpreter" is selected according the registry entry
> corresponding to the extension, the same as if you had double-clicked
> on the file's icon from an Explorer window.
> So, if we were to add ".sh" extensions to all of the scripts, and add
> ".sh" to PATHEXT, calling e.g. system("r.out.gdal ...") should run
> r.out.gdal.sh using the program associated with ".sh" in the registry.

Yes, I can confirm that this works. I guess we can handle the change to 
%PATHEXT% in a batch file that starts GRASS; FWIW here's what I had to do 
to set up the file association:
Open any Windows Explorer window
Go to Tools --> Folder Options --> File Types
Click New, type sh for the extension and click OK
Click on the new SH/SH File item in the list and click Advanced
Pick an icon, Enter "Bourne Shell Script" or something similar in the text 
box at the top of the dialog box.
Click New.. to create a new action
Put run for the action name and in "Application used to perform action" 
type: (keep the quotes):
"c:\msys\bin\sh.exe" "%1" %*
where c:\msys\bin\sh.exe is the path to your shell interpreter.
Click OK, OK again and close.

And then with PATHEXT and a few other environment variables set up 
properly you should be able to run GRASS scripts (as well as other GRASS 
commands) from a Windows command prompt. Other variables that are probably 

Unfortunately, Tcl seems to ignore the PATHEXT variable and according to 
http://www.tcl.tk/man/tcl8.4/TclCmd/exec.htm is hardcoded to only look for 
executable files with .com, .exe and .bat extensions. (Tcl is actually 
quite annoying.) But that's a problem for another day (which actually 
might involve forgetting about everything else above!).


More information about the grass-dev mailing list