Right now, we have run into a peculiar situation.
Basically, what we have is this:
launch.tcl:
proc start {filename args} {
eval exec [auto_execok start] "" [list [file nativename $filename]
$args]
}
set pcname 123
set username xyz
start test.bat $pcname $username
test.bat:
echo %1
sleep 120
What we see, when we run launch.tcl, is test.bat's echo displays %1
as
"123 xyz"
What we wanted was for %1 to be 123 and %2 to be xyz.
Note that the proc has an eval, what else needs to be done here?
Thanks !
> }
>
> set pcname 123
> set username xyz
> start test.bat $pcname $username
>
> test.bat:
>
> echo %1
> sleep 120
>
> What we see, when we run launch.tcl, is test.bat's echo displays %1
> as
> "123 xyz"
>
> What we wanted was for %1 to be 123 and %2 to be xyz.
>
> Note that the proc has an eval, what else needs to be done here?
>
> Thanks !
>
proc start {filename args} {
set execmd [ linsert $args 0 exec [auto_execok start] "" [file nativename $filename]
eval $execmd
or
if 1 $execmd
}
> > launch.tcl:
> > proc start {filename args} {
> > eval exec [auto_execok start] "" [list [file nativename $filename]
> > $args]
>
> wouldn't that look like
> xyznative {arg1 arg2 arg3}
> in the eval
>
>
>
> > }
>
>
> proc start {filename args} {
>
> set execmd [ linsert $args 0 exec [auto_execok start] "" [file nativename $filename]
>
> eval $execmd
> or
> if 1 $execmd
>
> }
See, my problem is that I'm just learning about bat files. And the
code that I list above was pieced together from the wiki and my feeble
attempt to extend it. So you are probably correct. hold on and I will
check...
No, that doesn't work. Now it doesn't execute at all! It is really a
pain for the error popup window generated to be done in a way that I
can't copy the text from it with my mouse... anyways:
Error in startup script
couldn't execute "C:\WINNT\system32\cmd.exe \c start": no such file or
directory
while executing
"exec {C:/WINNT/system32/cmd.exe /c start" {} {c:DAS\lwv27\Desktop
\test.bat} 123 xyz:
("eval" body line 1)
invoked from within
"eval $execmd"
(procedure "start" line 4)
invoked from within
"start c:DAS/lwv27/Desktop/test.bat $pcname $username"
(file "C:\Documents and Settings\lwv27\My Documents\MySoftware\Tcl
\launchbat.tk" line 12)
is close to exactly what the error box says.
Hi Larry,
FYI - you can copy the entire content from most Windows dialogs by...
- Make sure the dialog has focus
- Press Ctrl+C to copy the content to the clipboard
- Press Ctrl+V to paste the content elsewhere...
HTH,
Jeff
I believe you want
eval exec [auto_execok start] "" [list [file nativename
$filename]] $args
-Alex
Or even
The empty {""} argument to 'start' is actually significant.
Other approaches include:
eval [concat [auto_execok start] [list "" [file nativename $filename]] $args]
(for tcl8.5)
eval [list {*}[auto_execok start] "" [file nativename $filename] {*}$args]
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
1) it *in* ineffective in the OP's code since it gets swallowed by the
concatenation in [eval]
2) when it is really passed to cmd /c, what does "" do ?
> Other approaches include:
> eval [concat [auto_execok start] [list "" [file nativename $filename]] $args]
> (for tcl8.5)
> eval [list {*}[auto_execok start] "" [file nativename $filename] {*}$args]
Since [eval] is documented as concatenating its multiple arguments, I
really don't see the point of proposing variants which are more
complex and/or depend on the bleeding edge of syntactic sugar (I have
nothing against sugar -- except when it doesn't help readability).
-Alex
if the first argument to start contains a space, start assumes it is
intended to be the window title. Including the empty string as the
first argument forces start to use it as the window title, and to use
the rest of the arguments as the thing to start.
I stumbled over this when I:
- installed activeTcl under "c:\program files" (with a space)
- launched tkcon and
- click the "activetcl help" item from the help menu
see tkcon bug 1408425 at http://sourceforge.net/tracker/index.php?func=detail&aid=1408425&group_id=11462&atid=111462
and also http://wiki.tcl.tk/auto_execok
> eval [concat [auto_execok start] [list "" [file nativename $filename]] $args]
>
Is there some benefits of this over:
eval exec [auto_execok start] [list [list ] [file nativename
$filename] ] $args
or
eval exec [auto_execok start] [list {} [file nativename $filename] ]
$args
Just trying to understand the issues.
Frankly - it seems to me that if it is THIS hard to start a program on
Windows, this sort of thing should be included in the standard Tcl
distribution.
Note that apart from these issues, calling a bat file has an
additional complication in the way it treats arguments with comma's.
If an argument contains a comma, the batch file will get this passed
as multiple arguments. E.g. calling:
start test.bat a,b
will pass a and b as seperate arguments.
See http://wiki.tcl.tk/16336 for some possible workarounds
Mark
(oops, omitted 'exec' up there)
> Is there some benefits of this over:
>
> eval exec [auto_execok start] [list [list ] [file nativename
> $filename] ] $args
> or
> eval exec [auto_execok start] [list {} [file nativename $filename] ]
> $args
I wouldn't think so. I'm just picky about passing a list to eval (and
catch). Not that I peruse the eval man page again, I see my use of
concat is entirely redundant.
> Frankly - it seems to me that if it is THIS hard to start a program on
> Windows, this sort of thing should be included in the standard Tcl
> distribution.
It's not windows specifically. The [eval exec] combo is extremely
powerful but can be tricky to harness.
Notice that in 8.5 this becomes
exec {*}[auto_execok start] "" [file nativename $fn] {*}$args
which is admittedly a step forward in readability...
(though untested, not installed 8.5b yet)
-Alex
Notice that in 8.5 this becomes
exec {*}[auto_execok start] "" [file nativename $fn] {*}$args
which is admittedly a step forward in readability...
(though untested -- not installed 8.5b yet)
-Alex
Tested and confirmed: works for me.