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

exec output to a tcl/tk variable

664 views
Skip to first unread message

RDBMS4 (ORLANDO)

unread,
Mar 8, 1997, 3:00:00 AM3/8/97
to

I am trying to put a tk front-end to a program and need some help.

Basically I want the output from the program that I execute through the
exec command to be stored in a tcl/tk variable. I can then use that
variable in a message box as the text parameter.

Here is the code I am working with:

proc acknowledge {} {
set msg "This is a test"
tk_messageBox -default ok -icon info -message $msg -parent . \
-title Acknowledge -type ok
}

proc sendit {} {
global user
global type
set msg [.msgEnt get]
set action [string tolower $type]
set exe "/export/home/usupport/ORATOOLS/bin/$action"
catch acknowledge
exec $exe \"$msg\" $user ">/dev/null" "2>&1"
clearit
}

When this procedure gets executed it puts a message on another users
terminal. When the user clicks ok, the executed program sends a message
back to me through stderr to the xterm that I run the executable from. I
need a way to capture this info coming back into stderr so that I can
use it in the tcl program.

I have looked at tkerror/bgerror and catch but without much luck. The
catch seems to kind of work, but as soon as the executable program is
ran 'catch' senses that something is on stderr and kicks in. That is
correct, but at the time it starts, nothing has been written to stderr
yet.

Please email me directly as I am not on the comp.lang.tcl newsgroup.

Mike Campbell
mlca...@us.oracle.com

Cameron Laird

unread,
Mar 9, 1997, 3:00:00 AM3/9/97
to

In article <3321F1...@us.oracle.com>,

RDBMS4 (ORLANDO) <rdb...@us.oracle.com> wrote:
>I am trying to put a tk front-end to a program and need some help.
>
>Basically I want the output from the program that I execute through the
>exec command to be stored in a tcl/tk variable. I can then use that
.
.
.

>proc sendit {} {
> global user
> global type
> set msg [.msgEnt get]
> set action [string tolower $type]
> set exe "/export/home/usupport/ORATOOLS/bin/$action"
> catch acknowledge
> exec $exe \"$msg\" $user ">/dev/null" "2>&1"
> clearit
>}
>
>When this procedure gets executed it puts a message on another users
>terminal. When the user clicks ok, the executed program sends a message
>back to me through stderr to the xterm that I run the executable from. I
>need a way to capture this info coming back into stderr so that I can
>use it in the tcl program.
>
>I have looked at tkerror/bgerror and catch but without much luck. The
>catch seems to kind of work, but as soon as the executable program is
>ran 'catch' senses that something is on stderr and kicks in. That is
>correct, but at the time it starts, nothing has been written to stderr
>yet.
.
.
.
I'm having a hard time relating the source to some of your
description. I'll put some of it in my own words, solve
that problem, and hope that that gets you closer to where
you want to be.

You have a shell-level command

/export/home/usupport/ORATOOLS/bin/$action

You want to launch it with two arguments, $msg, and $user.
$msg might have embedded white space, but not embedded double-
quotes. You know that .../$action will put its results on
stderr. You want to collect those results into a text variable.

Do this:
catch {/export/home/usupport/ORATOOLS/bin/$action \
"$msg" $user >/dev/null} text_result

"$text_result" now holds the output you seek.
--

Cameron Laird http://starbase.neosoft.com/~claird/home.html
cla...@NeoSoft.com +1 713 623 8000 #227
+1 713 996 8546 FAX

Srinivasan Krishnamurthy

unread,
Mar 11, 1997, 3:00:00 AM3/11/97
to RDBMS4 (ORLANDO)

RDBMS4 (ORLANDO) wrote:
>
> I am trying to put a tk front-end to a program and need some help.
>
> Basically I want the output from the program that I execute through the
> exec command to be stored in a tcl/tk variable. I can then use that
> variable in a message box as the text parameter.
>
> Here is the code I am working with:
>
> proc acknowledge {} {
> set msg "This is a test"
> tk_messageBox -default ok -icon info -message $msg -parent . \
> -title Acknowledge -type ok
> }
>
> proc sendit {} {
> global user
> global type
> set msg [.msgEnt get]
> set action [string tolower $type]
> set exe "/export/home/usupport/ORATOOLS/bin/$action"
> catch acknowledge
> exec $exe \"$msg\" $user ">/dev/null" "2>&1"
> clearit
> }
>
> When this procedure gets executed it puts a message on another users
> terminal. When the user clicks ok, the executed program sends a message
> back to me through stderr to the xterm that I run the executable from. I
> need a way to capture this info coming back into stderr so that I can
> use it in the tcl program.
>
> I have looked at tkerror/bgerror and catch but without much luck. The
> catch seems to kind of work, but as soon as the executable program is
> ran 'catch' senses that something is on stderr and kicks in. That is
> correct, but at the time it starts, nothing has been written to stderr
> yet.
>
> Please email me directly as I am not on the comp.lang.tcl newsgroup.
>
> Mike Campbell
> mlca...@us.oracle.com

Hi mike
Don't know if you have gotten a reply already
But here you are:
set execResult [exec <cmd>]
should work the way you want it. You can then use "execResult" as a
variable. and do "string .." stuff on it.
-sre...@agcs.com, ku...@hotmail.com
(Srinivasan Krishnamurthy)

0 new messages