|
|
 |
 |
 |
 |
TCL(Tool Command Language) Scripting
|
 |
 |
 |
 |
 |
 |
 |
 |
ISO: technique to pass multiple arguments to a windows bat file
over at http://wiki.tcl.tk/18437 I have been writing my adventures in helping a friend write an application which would have a series of buttons and text entries, etc. designed to gather info from a user and then to pass relevant info to one of several possible bat files. 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 !
Larry W. Virden wrote: > over at http://wiki.tcl.tk/18437 I have been writing my adventures in > helping a friend write an application which would have a series of > buttons and text entries, etc. designed to gather info from a user and > then to pass relevant info to one of several possible bat files. > 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]
wouldn't that look like xyznative {arg1 arg2 arg3} in the eval
> } > 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
}
On Jun 6, 12:11 pm, Uwe Klein <uwe_klein_habertw@t-online.de> wrote:
> Larry W. Virden wrote: > > 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.
"Larry W. Virden" <lvir@gmail.com> wrote in message news:1181147117.674894.162790@w5g2000hsg.googlegroups.com... > On Jun 6, 12:11 pm, Uwe Klein <uwe_klein_habertw @t-online.de> > wrote: >> Larry W. Virden wrote: > 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:
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
On Jun 6, 6:02 pm, "Larry W. Virden" <lvir@gmail.com> wrote: > eval exec [auto_execok start] "" [list [file nativename $filename] $args] > What we wanted was for %1 to be 123 and %2 to be xyz.
I believe you want eval exec [auto_execok start] "" [list [file nativename $filename]] $args -Alex
On Jun 6, 7:02 pm, Alexandre Ferrieux <alexandre.ferri@gmail.com> wrote: > I believe you want > eval exec [auto_execok start] "" [list [file nativename > $filename]] $args
Or even eval exec [auto_execok start] [list [file nativename $filename]] $args -Alex
At 2007-06-06 01:27PM, "Alexandre Ferrieux" wrote: > On Jun 6, 7:02 pm, Alexandre Ferrieux <alexandre.ferri @gmail.com> > wrote: > > I believe you want > > eval exec [auto_execok start] "" [list [file nativename > > $filename]] $args > Or even > eval exec [auto_execok start] [list [file nativename $filename]] > $args
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
On Jun 6, 10:55 pm, Glenn Jackman <gle@ncf.ca> wrote: > The empty {""} argument to 'start' is actually significant.
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
At 2007-06-06 05:28PM, "Alexandre Ferrieux" wrote: > On Jun 6, 10:55 pm, Glenn Jackman <gle @ncf.ca> wrote: > > The empty {""} argument to 'start' is actually significant. > 2) when it is really passed to cmd /c, what does "" do ?
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&grou... and also http://wiki.tcl.tk/auto_execok -- Glenn Jackman "You can only be young once. But you can always be immature." -- Dave Barry
On Jun 6, 4:55 pm, Glenn Jackman <gle@ncf.ca> wrote: > 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.
On Jun 7, 1:48 pm, "Larry W. Virden" <lvir@gmail.com> wrote:
> On Jun 6, 4:55 pm, Glenn Jackman <gle @ncf.ca> wrote: > > 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
At 2007-06-07 07:48AM, "Larry W. Virden" wrote: > On Jun 6, 4:55 pm, Glenn Jackman <gle @ncf.ca> wrote: > > eval [concat [auto_execok start] [list "" [file nativename $filename]] $args]
(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. -- Glenn Jackman "You can only be young once. But you can always be immature." -- Dave Barry
On Jun 7, 1:48 pm, "Larry W. Virden" <lvir@gmail.com> wrote: > eval exec [auto_execok start] [list [list ] [file nativename > $filename] ] $args > 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.
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
On Jun 7, 1:48 pm, "Larry W. Virden" <lvir@gmail.com> wrote: > eval exec [auto_execok start] [list [list ] [file nativename > $filename] ] $args > 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.
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
At 2007-06-07 02:54PM, "Alexandre Ferrieux" wrote: > On Jun 7, 1:48 pm, "Larry W. Virden" <lvir @gmail.com> wrote: > > eval exec [auto_execok start] [list [list ] [file nativename > > $filename] ] $args > 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)
Tested and confirmed: works for me. -- Glenn Jackman "You can only be young once. But you can always be immature." -- Dave Barry
|
 |
 |
 |
 |
|