[GRASS-dev] Re: MS-Windows native GRASS

Thanks for this clarification. Now I have a couple more specific questions.

From: Glynn Clements <glynn@gclements.plus.com>
Date: Mon, 18 Sep 2006 11:32:12 +0100
To: Michael Barton <michael.barton@asu.edu>
Cc: Huidae Cho <grass4u@gmail.com>
Subject: Re: MS-Windows native GRASS

Michael Barton wrote:

Can you give an example of how you need to run a bash script under windows?

If $cmd is a script, you need to explicitly specify the interpreter.
E.g.:

exec $cmd $arg1 $arg2

needs to be changed to:

exec sh $cmd $arg1 $arg2 # for a shell script
or:

This should go into the runandoutput.tcl procedures. Can this be used for
all systems, or do I need to specify that this syntax is for mysys platforms
only? env(HOSTTYPE)=???

exec $env(GRASS_WISH) $cmd $arg1 $arg2 # for a Tcl/Tk script
etc.

Running a tcltk script from within tcltk shouldn't need this should it
(i.e., from within a WISH environment)? Calling wish should only be
necessary when starting a tcltk script from the command line or its
equivalent in mysys, right? This would be in the gis.m script.

Note that:

exec sh -c "$cmd $arg1 $arg2"

will work in some cases, but not all, so shouldn't be used.

Sorry, but I don't quite get it yet. You suggest that this same syntax also
runs under unix. Under Linux? Mac? I'm happy to test it on the Mac and at
least a flavor or two of Linux.

It's unnecessary under Unix (including OSX); you can just execve() a
script, and the kernel will detect the #!/bin/sh and invoke /bin/sh
automatically.

This isn't the case on Windows. Unix emulation layers (e.g. Cygwin,
MinGW's bash) include specific code to detect scripts and invoke the
interpreter.

So it's an issue with mysys only? Does it hurt to specify sh up front for
ALL, or do we need to do this only for mysys platforms?

Thanks

--
Glynn Clements <glynn@gclements.plus.com>

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

Michael Barton wrote:

>> Can you give an example of how you need to run a bash script under windows?
>
> If $cmd is a script, you need to explicitly specify the interpreter.
> E.g.:
>
> exec $cmd $arg1 $arg2
>
> needs to be changed to:
>
> exec sh $cmd $arg1 $arg2 # for a shell script
> or:

This should go into the runandoutput.tcl procedures. Can this be used for
all systems, or do I need to specify that this syntax is for mysys platforms
only? env(HOSTTYPE)=???

The problem is: how do you know whether $cmd is a script or a binary
executable?

On Unix, it doesn't matter; you can execute scripts just like binary
executables.

For Windows, there are a couple of options:

1. Add extensions (.sh, .tcl etc) to scripts, ensure that the
appropriate interpreters are associated with those extensions, and add
those extensions to PATHEXT. Then, executing "foo" will look for
foo.sh and foo.tcl in addtion to foo.exe, foo.cmd etc. Adding the
extensions would have to be done only for Windows; we don't want to
have to type the extensions on Unix.

2. Create a wrapper for executing commands, which automatically
detects scripts and invokes the appropriate interpreter. Replace usage
of Tcl's exec/open commands with our own versions which invoke the
wrapper on Windows.

> exec $env(GRASS_WISH) $cmd $arg1 $arg2 # for a Tcl/Tk script
> etc.

Running a tcltk script from within tcltk shouldn't need this should it
(i.e., from within a WISH environment)?

It does if you want to run it as a separate process, rather than
"source" it into the current wish process.

Calling wish should only be
necessary when starting a tcltk script from the command line or its
equivalent in mysys, right?

MSys' bash autodetects scripts and invokes the interpreter
automatically. Cygwin's execve() behaves similarly.

It's only an issue if you are executing commands using the native
Windows calls, e.g. spawnl() or CreateProcess(), which is what Tcl's
exec/open commands will use for a native Windows version of Tcl/Tk.

> Note that:
>
> exec sh -c "$cmd $arg1 $arg2"
>
> will work in some cases, but not all, so shouldn't be used.
>
>> Sorry, but I don't quite get it yet. You suggest that this same syntax also
>> runs under unix. Under Linux? Mac? I'm happy to test it on the Mac and at
>> least a flavor or two of Linux.
>
> It's unnecessary under Unix (including OSX); you can just execve() a
> script, and the kernel will detect the #!/bin/sh and invoke /bin/sh
> automatically.
>
> This isn't the case on Windows. Unix emulation layers (e.g. Cygwin,
> MinGW's bash) include specific code to detect scripts and invoke the
> interpreter.

So it's an issue with mysys only?

Specifying the interpreter is only required for a native Windows
environment.

Does it hurt to specify sh up front for
ALL, or do we need to do this only for mysys platforms?

You only use "sh" for shell scripts, not binary executables or scripts
written in other languages.

--
Glynn Clements <glynn@gclements.plus.com>