Using ecosadmin.tcl with the latest Cygwin Tcl shell
Jonathan Larmour
jifl@eCosCentric.com
Tue Jan 28 02:44:00 GMT 2003
John Dallaway wrote:
> The best solution I can find to the generic problem of invoking a Tcl
> script directly from (say) a bash shell while preserving both spaces
> in command-line arguments and null arguments uses commands of the form:
>
> exec tclsh \"${0}\" ${1+\"${1}\"} ${2+\"${2}\"} ${3+\"${3}\"} ${4+\"${4}\"} ${5+\"${5}\"}
>
> The above will faithfully process a script invocation such as:
>
> bash$ ./my\ script.tcl arg1 arg\ 2 "" arg4
Hmm... I don't like this - I'm sure it's possible to do better - so I had
a look. The following test script works:
#!/bin/sh
# \
exec sh -c 'if ( echo | cygtclsh80 ) 2>/dev/null ; then \
exec cygtclsh80 "${0}" "$@" ; \
fi' "$0" "$@"
puts "Started."
puts "argv0 = $argv0"
set argc 0
array set args {}
foreach arg $argv {
set args([incr argc]) $arg
}
for { set i 1 } { $i <= $argc } { incr i } {
puts "argv $i = $args($i)"
}
set fd [open $args(1)]
puts "Opened."
puts [gets $fd ]
puts "Printed."
I tried it with, for example:
$ test\ dir/foo.tcl test\ dir/space\ dir/test\ file arg\ 2 "" arg4
Started.
argv0 = test dir/foo.tcl
argv 1 = test dir/space dir/test file
argv 2 = arg 2
argv 3 =
argv 4 = arg4
Opened.
hi
Printed.
which, with an appropriate setup, as you can see works fine. So John, can
you verify for yourself and please do the honours :-). Note the extra
magic at the end of the exec line. This was the key!
Goodness knows how long I've spent on this preamble over the years! I
really hope this is the last time. I suppose it's my own fault as I think
I wrote the first version originally.
> The 'cygpath' processing added by Tim Michals' patches is useful but
> should be undertaken in the body of the Tcl script, not here. Otherwise,
> the behaviour of the Tcl script when invoked directly from (say) a
> bash shell will differ from that when invoked as a command line argument
> of the Tcl shell. The appended patch accommodates UNIX-style paths when
> adding an eCos package under Cygwin.
Fair point. Obviously please include that.
Jifl
--
eCosCentric http://www.eCosCentric.com/ <info@eCosCentric.com>
--[ "You can complain because roses have thorns, or you ]--
--[ can rejoice because thorns have roses." -Lincoln ]-- Opinions==mine
More information about the Ecos-patches
mailing list