Open GUI transcript window

B

bxb7668

I have been given a requirement for a perl script that runs on both
Windows and UNIX (AIX) from both the command line (UNIX) and the
Windows Start menu. It can take a long time to run, so they also want
it to write intermediate status messages. For the command line I just
write to STDOUT. No problem. But in the Windows GUI environment they
want a text window to open and the status message dynamically written
to it and show up as they are written, not when the entire process is
complete. Can this be done, and if so, how? We're using Perl 5.6.1.
Brian
 
P

Paul Lalli

I have been given a requirement for a perl script that runs on both
Windows and UNIX (AIX) from both the command line (UNIX) and the
Windows Start menu. It can take a long time to run, so they also want
it to write intermediate status messages. For the command line I just
write to STDOUT. No problem. But in the Windows GUI environment they
want a text window to open and the status message dynamically written
to it and show up as they are written, not when the entire process is
complete. Can this be done, and if so, how? We're using Perl 5.6.1.
Brian

Is there anything wrong with the CMD.exe window that normally comes up
when you write to STDOUT? If Windows is configured to associate .pl or
..plx files with the Perl interpreter, and you click that perl script from
the Start menu, any prints to STDOUT will show up in the black command
line window.

If this is not acceptable, for some reason, and the requirement is for
something more like a Notepad-style window, then you're delving into the
world of Perl/Tk. You might want to ask in comp.lang.perl.tk instead.

Paul Lalli
 
B

bxb7668

Thanks. I'll give it a try.
Brian

zentara said:
I have been given a requirement for a perl script that runs on both
Windows and UNIX (AIX) from both the command line (UNIX) and the
Windows Start menu. It can take a long time to run, so they also want
it to write intermediate status messages. For the command line I just
write to STDOUT. No problem. But in the Windows GUI environment they
want a text window to open and the status message dynamically written
to it and show up as they are written, not when the entire process is
complete. Can this be done, and if so, how? We're using Perl 5.6.1.
Brian

Try this preferred method with fileevent. But sometimes you need to
use Tk::after widget to read the output, if the sender program is
having pipe buffering problems. Fileevent is a built-in IO::Select
fot Tk. Read it's perldoc. Filevent will hang sometimes with pipe-buffer
problems.
########################################################
#!/usr/bin/perl
use warnings;
use strict;
use Tk;

open(CHILD, "./fileevent2piper 2>&1 |") or die "Can't open: $!";

my $mw = new MainWindow;

my $t = $mw->Scrolled("Text",-width => 80, -height => 25, -wrap =>
'none');
$t->pack(-expand => 1);

$mw->fileevent(\*CHILD, 'readable', [\&fill_text_widget,$t]);
MainLoop;

sub fill_text_widget {
my($widget) = @_;
$_ = <CHILD>;
$widget->insert('end', $_);
$widget->yview('end');
}
__END__
###########################################################

##HERE IS THE SENDER PROGRAM
##fileevent2piper

#!/usr/bin/perl

$|++;

for my $i ( 0 .. 10) {
print $i, "\n";
sleep 1;
}

print "sleeping 5\n";
sleep 5;

for my $i ( 0 .. 10) {
print $i, "\n";
sleep 1;
}

__END__
########################################################
 
B

bxb7668

Zentara,
Thank you. This does almost everything that I need. Just one more
thing. How do I close the new window when I'm done with it?
Brian

zentara said:
I have been given a requirement for a perl script that runs on both
Windows and UNIX (AIX) from both the command line (UNIX) and the
Windows Start menu. It can take a long time to run, so they also want
it to write intermediate status messages. For the command line I just
write to STDOUT. No problem. But in the Windows GUI environment they
want a text window to open and the status message dynamically written
to it and show up as they are written, not when the entire process is
complete. Can this be done, and if so, how? We're using Perl 5.6.1.
Brian

Try this preferred method with fileevent. But sometimes you need to
use Tk::after widget to read the output, if the sender program is
having pipe buffering problems. Fileevent is a built-in IO::Select
fot Tk. Read it's perldoc. Filevent will hang sometimes with pipe-buffer
problems.
########################################################
#!/usr/bin/perl
use warnings;
use strict;
use Tk;

open(CHILD, "./fileevent2piper 2>&1 |") or die "Can't open: $!";

my $mw = new MainWindow;

my $t = $mw->Scrolled("Text",-width => 80, -height => 25, -wrap =>
'none');
$t->pack(-expand => 1);

$mw->fileevent(\*CHILD, 'readable', [\&fill_text_widget,$t]);
MainLoop;

sub fill_text_widget {
my($widget) = @_;
$_ = <CHILD>;
$widget->insert('end', $_);
$widget->yview('end');
}
__END__
###########################################################

##HERE IS THE SENDER PROGRAM
##fileevent2piper

#!/usr/bin/perl

$|++;

for my $i ( 0 .. 10) {
print $i, "\n";
sleep 1;
}

print "sleeping 5\n";
sleep 5;

for my $i ( 0 .. 10) {
print $i, "\n";
sleep 1;
}

__END__
########################################################
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top