Problem with two Pipes, one for STDOUT and one for STDERR 
Author Message
 Problem with two Pipes, one for STDOUT and one for STDERR

Hello,

I want to exec a programm and will put the STDOUT in one widget an the
STDERR in another widget. I have write a source and it works fine. But
the Pipe for the STDERR doesn't end.
Does someone know what's my bug?

Here's the source:

    set pipeStdErr [open "|/bin/cat" r+]

    ###########
    #
    # STDERR
    #
    fileevent  $pipeStdErr readable {

        if {[eof $pipeStdErr]} {
# ??? this are not show ???
tk_messageBox -message "STDERR - END"
            catch {close $pipeStdErr}
            set waitForStdErr 1
        } elseif {[gets $pipeStdErr txt] >= 0} {
            p_copyStdErr $txt
        }
    }

    ###########
    #
    # STDOUT
    #
    fileevent  $pipeStdOut readable {

        if {[eof $pipeStdOut]} {
# ??? this are shown ???
tk_messageBox -message "STDOUT - END"
            catch {close $pipeStdOut}
            puts $pipeStdErr -1
            set waitForStdOut 1
        } elseif {[gets $pipeStdOut txt] >= 0} {
            p_showStdOut $txt
        }
    }

    # Wait for the End
    vwait waitForStdOut
    set waitForStdOut 0
# this blocks, because waitForStdErr will not be set
    vwait waitForStdErr
    set waitForStdErr 0

thanks,
Thomas



Sat, 02 Jul 2005 16:46:16 GMT  
 Problem with two Pipes, one for STDOUT and one for STDERR
Hi Thomas,

my first idea was to use cat -u for unbuffered output of cat.
But when I reread the Linux man page of cat, I found the -u
option is ignored. So I'm not sure, wether it helps. Just try it.

Best regards

Ulrich

Quote:

> Hello,

> I want to exec a programm and will put the STDOUT in one widget an the
> STDERR in another widget. I have write a source and it works fine. But
> the Pipe for the STDERR doesn't end.
> Does someone know what's my bug?

> Here's the source:

>     set pipeStdErr [open "|/bin/cat" r+]

>     ###########
>     #
>     # STDERR
>     #
>     fileevent  $pipeStdErr readable {

>         if {[eof $pipeStdErr]} {
> # ??? this are not show ???
> tk_messageBox -message "STDERR - END"
>             catch {close $pipeStdErr}
>             set waitForStdErr 1
>         } elseif {[gets $pipeStdErr txt] >= 0} {
>             p_copyStdErr $txt
>         }
>     }

>     ###########
>     #
>     # STDOUT
>     #
>     fileevent  $pipeStdOut readable {

>         if {[eof $pipeStdOut]} {
> # ??? this are shown ???
> tk_messageBox -message "STDOUT - END"
>             catch {close $pipeStdOut}
>             puts $pipeStdErr -1
>             set waitForStdOut 1
>         } elseif {[gets $pipeStdOut txt] >= 0} {
>             p_showStdOut $txt
>         }
>     }

>     # Wait for the End
>     vwait waitForStdOut
>     set waitForStdOut 0
> # this blocks, because waitForStdErr will not be set
>     vwait waitForStdErr
>     set waitForStdErr 0

> thanks,
> Thomas

--
SIGOS Systemintegration GmbH
 - TESTING IS OUR COMPETENCE -
Fon +49 911 95168-0
www.sigos.de

Visit us at the 3GSM World Congress 2003 in Cannes, France
February 17 - 21 , in hall 2 stand E5



Sat, 02 Jul 2005 20:18:45 GMT  
 Problem with two Pipes, one for STDOUT and one for STDERR

Quote:

> I want to exec a programm and will put the STDOUT in one
> widget an the STDERR in another widget.

Take a look at http://wiki.tcl.tk/stderr for a suggestion.

Bob
--

Mayo Foundation                                 (507) 538-5495
200 First St. SW                            FAX (507) 284-9171
Rochester MN, 55901  USA            http://www.mayo.edu/sppdg/



Sat, 02 Jul 2005 21:24:02 GMT  
 Problem with two Pipes, one for STDOUT and one for STDERR

Quote:

> Take a look at http://wiki.tcl.tk/stderr for a suggestion.

> Bob

Thanks Bob,

But at this Site are only shown, how put STDOUT and STDERR together.

And bgerror cannot be used:
"But for Tk applications, a problem occurs when the program takes time
to process."
(from http://www-bio3d-igbmc.u-strasbg.fr/doclib/blt/bgexec.html )

I want programm a tk-windows which call a c-programm and puts the
STDOUT on one Windows and the STDERR on another. And this must be
happend just-in-time and up to one hour.

Thomas.



Sun, 03 Jul 2005 16:47:11 GMT  
 Problem with two Pipes, one for STDOUT and one for STDERR

Quote:

> Hi Thomas,

> my first idea was to use cat -u for unbuffered output of cat.
> But when I reread the Linux man page of cat, I found the -u
> option is ignored. So I'm not sure, wether it helps. Just try it.

> Best regards

> Ulrich

Thanks but it don't work anyway,

I had take this ingnored option and configure my pipe with

fconfigure $pipeStdErr -buffering none -blocking no

but without procees.
The STDERR-Pipe doesn't end.

Thomas.



Sun, 03 Jul 2005 16:57:35 GMT  
 Problem with two Pipes, one for STDOUT and one for STDERR

| I want to exec a programm and will put the STDOUT in one widget an
| the STDERR in another widget. I have write a source and it works
| fine. But the Pipe for the STDERR doesn't end.  Does someone know
| what's my bug?
--<snip-snip>--
|     set pipeStdErr [open "|/bin/cat" r+]

It's not a bug, it's a feature :-) You still have the write end of the
pipe to `cat' open, so of course `cat' does not exit.  AFAIK there is
no way to only close the write end and leave the reading end open on
TCL level.  If you simply `close' it, any input might get lost, so
better call flush before closing.

General scheme:
- after stdout is closed, you know that the process has exited
- then flush stderr (this will trigger the fileevents)
- and close the channel

    # Wait for the End
    vwait waitForStdOut
    # process has exited now, could even do this in the eof branch of
    # the stdout filehandler
    flush $pipeStdErr  ;# triggers fileevents on stderr
    catch {close $pipeStdErr}  ;# close remaining open fd to `cat'

I would rather redirect stderr to a temp file and call `tail -f' on
that file if you need it immediately.  Note that if you only need it
after $command has exited, you can just use `catch close' to get the
stderr output.  If you have C-level access, then just pipe/fork the
subcommands yourself.

R'



Sun, 03 Jul 2005 21:40:16 GMT  
 Problem with two Pipes, one for STDOUT and one for STDERR


:I want to exec a programm and will put the STDOUT in one widget an the
:STDERR in another widget.

Does it _have_ to all be written in script?

And are you just interested in seeing the info, or is it required
to see it 'in real time' (well, as it is output from the application),
as opposed to at the end of the application?
--
Tcl - The glue of a new generation.  <URL: http://wiki.tcl.tk/ >
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.



Mon, 04 Jul 2005 00:27:24 GMT  
 Problem with two Pipes, one for STDOUT and one for STDERR

Quote:


>>Take a look at http://wiki.tcl.tk/stderr for a suggestion.

>>Bob

> Thanks Bob,

> But at this Site are only shown, how put STDOUT and STDERR together.

> And bgerror cannot be used:
> "But for Tk applications, a problem occurs when the program takes time
> to process."
> (from http://www-bio3d-igbmc.u-strasbg.fr/doclib/blt/bgexec.html )

bgerror is something entirely different than bgexec. And the quote
is talking about issues with TCL exec which bgexec handles. In your case
bgexec with -onoutput & -onerror would seem to be exactly what you
want. Is there a reason you can't use BLT ?

Bruce

- Show quoted text -

Quote:

> I want programm a tk-windows which call a c-programm and puts the
> STDOUT on one Windows and the STDERR on another. And this must be
> happend just-in-time and up to one hour.

> Thomas.



Mon, 04 Jul 2005 03:45:18 GMT  
 Problem with two Pipes, one for STDOUT and one for STDERR

Quote:

> General scheme:
> - after stdout is closed, you know that the process has exited
> - then flush stderr (this will trigger the fileevents)
> - and close the channel

>     # Wait for the End
>     vwait waitForStdOut
>     # process has exited now, could even do this in the eof branch of
>     # the stdout filehandler
>     flush $pipeStdErr  ;# triggers fileevents on stderr
>     catch {close $pipeStdErr}  ;# close remaining open fd to `cat'

That's it.
Now all works fine.
Many thanks!


Tue, 05 Jul 2005 21:20:20 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. How to replace one or two words with one word with one line of awk code

2. Problem piping stderr and stdout with open command

3. One and One doesn't equal two It equals 1 - The Who

4. One and One doesn't equal two It equals 1 - The Who

5. Blt 2.3: One Bug, One Feature, Two Solutions :)

6. Two One bug, one RFE in Tk4.0

7. Piping stdout/stderr to RXQUEUE while keeping rc

8. Piping stdout & stderr to RXQUEUE

9. See one, do one, teach one...

10. Setting pipe for both stdout/stderr

11. Q:stdout & stderr piped to text widget

12. Q: How to open a pipe to redirect both stdout and stderr

 

 
Powered by phpBB® Forum Software