A bucket-load of XP to the monk that can make this work:
Original code:use strict; $|++; if( $ARGV[0] eq 'child' ) { sleep 1; print STDOUT "stdout1\n"; sleep 1; print STDOUT "stdout2\n"; sleep 1; print STDOUT "stdout3\n"; sleep 1; print STDOUT "stdout4\n"; exit; } use Tk; use Tk::ROText; my $mw = MainWindow->new; my $text = $mw->ROText()->pack( -fill => 'both', -expand => 1 ); use IO::Handle; my $stdout = IO::Handle->new(); my $pid = open( $stdout, "$0 child |" ) || die; $stdout->autoflush( 1 ); $mw->fileevent( $stdout, readable => \&read_stdout ); MainLoop; sub read_stdout { print "read_stdout()\n"; my $num = $stdout->sysread( my $buffer, 1024 ); print "sysread() got $num bytes:\n[$buffer]\n"; $text->insert( 'end', $buffer ); }
use strict; $|++; if( $ARGV[0] eq 'child' ) { sleep 1; print STDOUT "stdout1\n"; sleep 1; print STDERR "stderr1\n"; sleep 1; print STDOUT "stdout2\n"; sleep 1; print STDERR "stderr2\n"; exit; } use Tk; use Tk::ROText; my $mw = MainWindow->new; my $text = $mw->ROText()->pack( -fill => 'both', -expand => 1 ); $text->tagConfigure( 'red', -foreground => 'red' ); use IO::Handle; my $stdin = IO::Handle->new(); my $stdout = IO::Handle->new(); my $stderr = IO::Handle->new(); use IPC::Open3; my $pid = open3( $stdin, $stdout, $stderr, "$0 child" ) || die; $stdin->close; $stdout->autoflush( 1 ); $stderr->autoflush( 1 ); $mw->fileevent( $stdout, readable => \&read_stdout ); $mw->fileevent( $stderr, readable => \&read_stderr ); MainLoop; sub read_stdout { print "read_stdout()\n"; my $num = $stdout->sysread( my $buffer, 1024 ); print "sysread() got $num bytes:\n[$buffer]\n"; $text->insert( 'end', $buffer ); } sub read_stderr { print "read_stderr()\n"; my $num = $stderr->sysread( my $buffer, 1024 ); print "sysread() got $num bytes:\n[$buffer]\n"; $text->insert( 'end', $buffer, 'red' ); }
- ><iper
use japh; print;
In reply to capture output of a daemon in a tk widget on win32 by xiper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |