For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > June 2006 > console output









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author console output
Johannes Holzer

2006-06-24, 8:11 am

Hi

How do i get the output of a shell program (STDOUT and STDERR if
possible) into a widget in Perl/TK?

I want my GUI to start `rsync` and the user should get some kind of
feedback.

I didn't find this in the FAQ or via google. Anyone knows proper keywords?

johannes Holzer
QoS@domain.invalid.com

2006-06-24, 8:11 am


Johannes Holzer <hl.ichaus@arcor.de> wrote in message-id:
<9c0qm3-lhs.ln1@algic.ichaus.de>
>
>Hi
>
>How do i get the output of a shell program (STDOUT and STDERR if
>possible) into a widget in Perl/TK?
>
>I want my GUI to start `rsync` and the user should get some kind of
>feedback.
>
>I didn't find this in the FAQ or via google. Anyone knows proper keywords?
>
>johannes Holzer


One possibility would be to capture the output of the cli command
right there at the cli.

eg - rsync > text.txt

The above command should capture the rsync output to the file text.txt
Once/if that completes you could read the text document into your program.

Another possibility could be doing it similar to the way Tk::ExecuteCommand
does this.

Tk::ExecuteCommand runs a command yet still allows Tk events to flow. All
command output and errors are displayed in a window.



s.berndt@bk-cad.de

2006-06-24, 8:11 am


You may use a pipe to to get the STDOUT:

my $mycmd = "rsync ..."
open (PIPE, "$mycmd |");
while (my $cmdout = <PIPE> )
{
$textwidget->insert("end", "$cmdout");
$textwidget->see("end");
$textwidget->update();
}
close (PIPE);

you may have to redirect the STDERR to STDOUT within your command ...

I'm using it on Win32 and UNIX and it works fine ;-)

Johannes Holzer

2006-06-26, 7:02 pm

s.berndt@bk-cad.de schrieb:
> You may use a pipe to to get the STDOUT:
>
> my $mycmd = "rsync ..."
> open (PIPE, "$mycmd |");
> while (my $cmdout = <PIPE> )
> {
> $textwidget->insert("end", "$cmdout");
> $textwidget->see("end");
> $textwidget->update();
> }
> close (PIPE);
>
> you may have to redirect the STDERR to STDOUT within your command ...
>
> I'm using it on Win32 and UNIX and it works fine ;-)
>

Oh, it can be that easy... sorry to ask.

I also checked Tk::ExecuteCommand (see Posting of "QoS") - this version
seems to be a lot faster. Speed is not so important to me, so i will
prefer you simple version.

right now, i'm checking a third solution (from this newsgroup, May, 18th
2001 - MessageID 3B053844.6B0A2F07@sanger.ac.uk,
http://groups.google.de/group/comp....38a816914c0f033 ),
but for now this only works partially for me. It produced the following
errormessage on Exit:
(
Can't locate Tk/PRINT.pm in @INC (...) at
/usr/lib/perl5/vendor_perl/5.8.7/i586-linux-thread-multi/Tk/Widget.pm
line 261.
)
an does not yet caption stderr from external programs.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com