Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cannot read VBScript output from Tcl/Tk

82 views
Skip to first unread message

il.pall...@gmail.com

unread,
Sep 1, 2016, 6:18:07 AM9/1/16
to
Hello everybody.

I want to retrieve VBScript output from Tcl/Tk, but I have no results.
Can you help me?

This is the source of Tcl/Tk script:

# ----------Tcl/Tk: ActiveState ActiveTcl 8.5.13
proc ExecVbs {} {
global widget
set li {}
if {[file exists "Y:/TestStdOut.vbs"]} {
set io [open "|cmd /c cscript /nologo Y:/TestStdOut.vbs" r]
while {![eof $io]} {
gets $io line
lappend li $line
}
close $io
#set n_l [llength $li]
#tk_messageBox -message "Close OK, Length of ListBox: $n_l"
update
foreach el $li {
.lb1 insert end [string toupper $el]
}
update
} else {
tk_messageBox -message "VBS not found!"
}
}
# ------------------------MAIN-------------------------------
wm title . "TkCallVbs"
wm resizable . 0 0
wm geometry . 550x500+50+50;
listbox .lb1 -list ::list1
button .b1 -text "Run Me" -command {ExecVbs} -font "Arial 8"
place .lb1 -x 050 -y 50 -width 450 -height 400 -anchor nw -bordermode ignore
place .b1 -x 100 -y 10 -width 100 -anchor nw -bordermode ignore
update
focus -force .
# -------End Tcl/Tk

And this is the VBScript code:

rem ------ TestStdOut.vbs
rem
wscript.echo "Hello"
wscript.echo "I'm a"
wscript.echo "VBSCRIPT"
rem ------ End VBS


Thanks

Giorgio

Arjen Markus

unread,
Sep 1, 2016, 6:45:06 AM9/1/16
to
Op donderdag 1 september 2016 12:18:07 UTC+2 schreef il.pall...@gmail.com:
You should either use [exec] or [fileevent]:

set output [exec Y:/TestStdOut.vbs]

(then you get the output directly, but if the VBS command takes a while, your application freezes)

If you use [open "|...] you need to register an event handler with [fileevent]. See the Wiki (wiki.tcl.tk) for examples. The advantage is that your application can continue, while this VB script is running in the background.

Regards,

Arjen

pal...@yahoo.com

unread,
Sep 1, 2016, 8:46:18 AM9/1/16
to
Change your while loop to

while {[gets $io line] >= 0} {
lappend li $line
}

Since you have not changed the channel to non-blocking, that should be enough.

/Ashok

pal...@yahoo.com

unread,
Sep 1, 2016, 9:12:04 AM9/1/16
to
BTW, you do not need cmd /c, you can just call cscript directly

il.pall...@gmail.com

unread,
Sep 1, 2016, 9:42:04 AM9/1/16
to
Thank you.
I had to apply your both your tips!
Now it works.

Regards


Giorgio

il.pall...@gmail.com

unread,
Sep 1, 2016, 10:29:17 AM9/1/16
to
Ok, this is the working Tcl/Tk code:

proc ExecVbs {} {
global widget
set li {}
if {[file exists "Y:/TestStdOut.vbs"]} {
set io [open "| cscript /nologo Y:/TestStdOut.vbs" r]
while {[gets $io line] >= 0} {
lappend li $line
}
close $io
#set n_l [llength $li]
#tk_messageBox -message "Close OK, Length of ListBox: $n_l"
update
foreach el $li {
.lb1 insert end [string toupper $el]
}
update
} else {
tk_messageBox -message "VBS not found!"
}
}
# ------------------------MAIN-------------------------------
wm title . "TkCallVbs"
wm resizable . 0 0
wm geometry . 550x500+50+50;
listbox .lb1 -list ::list1
button .b1 -text "Run Me" -command {ExecVbs} -font "Arial 8"
place .lb1 -x 050 -y 50 -width 450 -height 400 -anchor nw -bordermode ignore
place .b1 -x 100 -y 10 -width 100 -anchor nw -bordermode ignore
update
focus -force .
#---------End Tcl/Tk

Thanks to everybody

Giorgio

Ralf Fassel

unread,
Sep 2, 2016, 5:28:34 AM9/2/16
to
* il.pall...@gmail.com
| set io [open "|cmd /c cscript /nologo Y:/TestStdOut.vbs" r]

I'm not 100% sure, but I *think* cmd /c requires a single argument,
like in

"|cmd /c [list cscript /nologo Y:/TestStdOut.vbs]"

However, better skip cmd /c as already discussed in the other messages.

R'

il.pall...@gmail.com

unread,
Sep 2, 2016, 5:29:57 AM9/2/16
to
In order to improve the graphical interface, I would not see the CMD window opened by the statement:

set io [open "| cscript /nologo Y:/TestStdOut.vbs" r]

when the VBS code runs for several tens of seconds.

Any suggestion?

Regards

Giorgio

Arjen Markus

unread,
Sep 2, 2016, 7:00:59 AM9/2/16
to
Op vrijdag 2 september 2016 11:29:57 UTC+2 schreef il.pall...@gmail.com:
I do not know anything about cscript, but I would look for an option that suppresses the creation of a console window. Perhaps /B does the job?

I observed an option /h:cscript and /h:wscript - wscript brings up a graphical window.

Anyway, it is the cscript program that is responsible for the popping up of the window, not Tcl/Tk itself.
0 new messages