Redirecting output of a exec'ed application 
Author Message
 Redirecting output of a exec'ed application

Hi,
I want to redirect both the standard output and standard error from
a command issued by the "exec" command from tcl, into a text widget.

I have found an example that redirects only the stdout, at the www
page http://www.*-*-*.com/ , but this
seems to be a bad solution. (The code i referr to is quoted at the end
of this message).
It looks like the fileevent starts to loop as soon as it gets something
to read. (And, it only reads from stdin, not the stderr of the app).
When should the created pipe be closed? How do I know when the app is
finished?

here's the referred example:

#!/usr/local/bin/wish

text .t -yscrollc {.sb set}
scrollbar .sb -command {.t yview}
button .b -text "Quit" -command {destroy .}

pack .sb -side right -fill y
pack .b -side bottom
pack .t -side left -fill both -expand 1

# Open the process we want to monitor hooked up to a pipe
# swap the #'s to enable 'foo | stdoutin.tcl':
set f [open "|stdoutin.pl" r]
#set f "stdin"

fileevent $f readable {
   .t insert end "[gets $f]\n"
   .t yview end
   update idletasks

Quote:
}

Sincerly,
Ludvig A. Norin

--

--- This is a sighfile.

From: Ludvig A. Norin


and : http://www.*-*-*.com/ ~no

--- So don't go do something stupid now, okay?



Tue, 15 Dec 1998 03:00:00 GMT  
 Redirecting output of a exec'ed application


: Hi,
: I want to redirect both the standard output and standard error from
: a command issued by the "exec" command from tcl, into a text widget.
:
: I have found an example that redirects only the stdout, at the www
: page http://www.sco.com/Technology/tcl/tkFragments.html, but this
: seems to be a bad solution. (The code i referr to is quoted at the end
: of this message).
: It looks like the fileevent starts to loop as soon as it gets something
: to read. (And, it only reads from stdin, not the stderr of the app).
: When should the created pipe be closed? How do I know when the app is
: finished?
:
: here's the referred example:
:
:
: #!/usr/local/bin/wish
:
: text .t -yscrollc {.sb set}
: scrollbar .sb -command {.t yview}
: button .b -text "Quit" -command {destroy .}
:
: pack .sb -side right -fill y
: pack .b -side bottom
: pack .t -side left -fill both -expand 1
:
:
: # Open the process we want to monitor hooked up to a pipe
: # swap the #'s to enable 'foo | stdoutin.tcl':
: set f [open "|stdoutin.pl" r]


    This will do the trick because the redirection of file descriptor
    2 (stderr) will be done internally with a dup2(2) AFTER the stdout
    is already redirected to the pipe.

: #set f "stdin"
:
: fileevent $f readable {
:    .t insert end "[gets $f]\n"
:    .t yview end
:    update idletasks
: }
:
: Sincerly,
: Ludvig A. Norin

Until later, Jan

--
#define OPINIONS "they are all mine - not those of debis or daimler-benz"

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #



Sat, 19 Dec 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Capturing output from exec'ed command

2. redirect exec output to a file

3. Redirect Output From exec to text widget

4. Redirecting Output With Exec

5. Using import in an exec'ed string

6. return val of exec'ed prog

7. interaction with exec'ed process

8. How to pass arguments to program been exec'ed

9. waiting for an exec'ed process to finish

10. Q: interacting with exec'ed commands ?

11. Redirect exec's STDOUT to textwidget

12. Can't redirect output from gnat-3.13p-nt

 

 
Powered by phpBB® Forum Software