in reply to Update Text Widget during FTP in Perl/Tk
This has come up so often, that the Tk::ExecuteCommand module was developed. Try running your ftp through Tk::ExecuteCommand. You could put your ftp code into a second helper script.
Another option is to use Tk::fileevent (whichs reads files in a non-blocking manner), and use IPC::Open3 to run the ftp stuff. There are other ways to use fileevent too, like the piped form of open. Here is some sample code showing how to integrate IPC::Open3,fileevent, and Tk.
#!/usr/bin/perl -w use strict 'vars'; #by John Drukman $|=1; use Tk; use IPC::Open3; local *IN; local *OUT; local *ERR; my $pid=open3(\*IN,\*OUT,\*ERR,'/bin/bash'); # set \*ERR to 0 to send STDERR to STDOUT my $inwin=new MainWindow; my $entry=$inwin->Entry(-width => 80)->pack; $inwin->Button(-text => 'Send', -command => \&send_to_shell)->pack; my $outwin=new MainWindow; my $textwin=$outwin->Text(-width => 80, -height => 24, -state => 'disabled')->pack; $outwin->fileevent(OUT,'readable',\&get_from); MainLoop; sub send_to_shell { my $cmd=$entry->get() . "\n"; write_textwin("> $cmd"); print IN $cmd; } sub get_from { my $buf=''; sysread OUT,$buf,4096; write_textwin($buf); } sub write_textwin { my $str=shift; $textwin->configure(-state=>'normal'); $textwin->insert('end',$str); $textwin->see('end'); $textwin->configure(-state=>'disabled'); } __END__
|
|---|