Prev: Tcl vs. Lua
Next: Checksum
From: Andry on
Hi,
I'm trying to create some scripts to run Ixia performance tests using a
console interface (tclsh) in place of a gui interface for input of test
parameters. Gui-based Ixia tests are basically Tcl/Tk scripts that can
be run using tcl packages (IxTclHal) only accessible from wish and not
from tclsh.
So, I proceeded creating a tcl script that, running from Tclsh, gets
the parameters (strings) from the user (gets stdin ...) and put the
values in a ".tcl" file that can be run from wish (the values are saved
as strings in the middle of IxTclHal commands).

My problem is the following:

If I open a Tclsh console and I manually try to launch wish console
(from tclsh console) using the simple command "% wish83.exe
scriptname.tcl", it works fine (wish console opens up and I can see the
script running on wish console).
If I try to use the same command as part of a tcl script that I run
from tclsh (the same script that collects user's input from console)
then I get the following error:
% invalid command name "wish83.exe"

I also tried with: % exec "wish83.exe test-choice.tcl", but I get the
folowing error:
% couldn't execute "wish83.exe test-choice.tcl": no such file or
directory

I also tried simply using: % exec "wish83.exe", but, in that case, wish
console opens up but the Output of the screen is redirected to Tclsh
stdout and it's not actually displayed until I manually exit from the
wish console and get back to Tclsh console. Btw, in this case the wish
console doesn't even show the "%" prompt. So, I can manually run the
script, but the output of the console will only be displayed after the
script is done and on the Tclsh instead.
For the purpose of my tests, I need to see the output of the script
real-time (although there is no user input needed once the script from
wish is launched).
I think this problem has to do with the fact that wish has no
stdin/stdout unlike tclsh.
But consider that, as I said before, if I manually launch wish from the
Tclsh console, it works.
How can I achieve the same result from inside the script?

In other words, how can I launch the wish console and start the script
automatically (through wish) using a Tcl script that is run through the
Tclsh console?

Thanks a lot,
Andrea

From: Glenn Jackman on
At 2006-02-17 03:24PM, Andry <yandry77(a)gmail.com> wrote:
> Hi,
> I'm trying to create some scripts to run Ixia performance tests using a
> console interface (tclsh) in place of a gui interface for input of test
> parameters. Gui-based Ixia tests are basically Tcl/Tk scripts that can
> be run using tcl packages (IxTclHal) only accessible from wish and not
> from tclsh.
[...]
> If I open a Tclsh console and I manually try to launch wish console
> (from tclsh console) using the simple command "% wish83.exe
> scriptname.tcl", it works fine (wish console opens up and I can see the
> script running on wish console).

In an interactive tclsh session, if you enter an unknown command the
interpreter will try it with "exec". It does this via the [unknown]
procedure. For interest, in an interactive tclsh session, enter "info
body unknown".

> I also tried with: % exec "wish83.exe test-choice.tcl", but I get the
> folowing error:
> % couldn't execute "wish83.exe test-choice.tcl": no such file or
> directory

[exec] takes arguments, the first of which is the external command to
run. As you have only 1 arg to exec, it was trying to look for a
program named "wish83.exe test-choice.tcl". Try:
exec wish83.exe test-choice.tcl


Try this in your tcl console:
package require Tk
source test-choice.tcl

Alternately, launch your wish program and read its stdout:

set pipe [open "| wish83.exe test-choice.tcl" r]
fileevent $pipe readable [list callback $pipe]
vwait ::forever

proc callback {chan} {
if {[gets $chan line] > -1} {
do something with $line
} else {
if {[eof $chan]} {
puts "program has ended"
set ::forever now
}
}
}


--
Glenn Jackman
Ulterior Designer
From: Andry on

Glenn Jackman wrote:
>
> [exec] takes arguments, the first of which is the external command to
> run. As you have only 1 arg to exec, it was trying to look for a
> program named "wish83.exe test-choice.tcl". Try:
> exec wish83.exe test-choice.tcl
OK

> Try this in your tcl console:
> package require Tk
> source test-choice.tcl
I also thought this could work, but actually this is not enough,
IxTclHal still cannot be used (my script starts with the command
"package require IxTclHal" which returns an error saying "cannot find
package"). Without that package I cannot run the rest of the
sub-scripts.

> Alternately, launch your wish program and read its stdout:
>
> set pipe [open "| wish83.exe test-choice.tcl" r]
> fileevent $pipe readable [list callback $pipe]
> vwait ::forever
>
> proc callback {chan} {
> if {[gets $chan line] > -1} {
> do something with $line
> } else {
> if {[eof $chan]} {
> puts "program has ended"
> set ::forever now
> }
> }
> }
Yes, this works really well! This is a very good solution for me.
Thank you so much.

From: Cameron Laird on
In article <1140220630.800091.313550(a)z14g2000cwz.googlegroups.com>,
Andry <yandry77(a)gmail.com> wrote:
>
>Glenn Jackman wrote:
>>
>> [exec] takes arguments, the first of which is the external command to
>> run. As you have only 1 arg to exec, it was trying to look for a
>> program named "wish83.exe test-choice.tcl". Try:
>> exec wish83.exe test-choice.tcl
>OK
>
>> Try this in your tcl console:
>> package require Tk
>> source test-choice.tcl
>I also thought this could work, but actually this is not enough,
>IxTclHal still cannot be used (my script starts with the command
>"package require IxTclHal" which returns an error saying "cannot find
>package"). Without that package I cannot run the rest of the
>sub-scripts.
.
.
.
You have me curious. Are you reporting that wish
handles
package require IxTclHal
but tclsh does not? Is your tclsh any happier with
the sequence
package require Tk
package require IxTclHal
?
From: suchenwi on
If IxTclHal needs Tk, it should require it itself, like BWidget does.

 |  Next  |  Last
Pages: 1 2 3 4
Prev: Tcl vs. Lua
Next: Checksum