markzango has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to use IPC::Run along with filevent under win32 to capture the output from a console command. The code I'm using looks like:
use Tk 800.000; use strict; use Tk::LineNumberText; use IPC::Run qw(start finish); my $MW = MainWindow->new; my $cmd_output = $MW->LineNumberText(-widget=>'ROText')->pack(-fill=>' +both',-expand=>1); my $harness = start(['cmd.exe','/C','echo hello'] , '<' ,\undef , ">pi +pe", \*OUT,debug=>999) || die $!; $MW->fileevent(\*OUT,'readable',[\&mycb,\*OUT,$harness]); MainLoop; sub mycb { $cmd_output->insert('end',"Callback called\n"); my ($fh, $harness) = @_; my $n = sysread( $fh, my $buf, 8192 ); if($n) { $cmd_output->insert('end',$buf); return; } $cmd_output->insert('end',"WARNING: $!") if not defined $n; $MW->fileevent( $fh, 'readable', '' ); close $fh; $harness->finish; }
Unfortunately, this doesn't seem to work for some reason. My understanding is that under Win32 select only works on sockets, and that IPC::Run uses sockets between processes to send information. Since fileevent uses select, I don't see why this isn't working. Debugging output:
IPC::Run 0000 0123-------- [#1(44744)]: debugging fd is 3 IPC::Run 0000 0123-------- [#1(44744)]: ** starting IPC::Run 0000 0123-------- [#1(44744)]: 'cmd.exe' added to cache: 'C:\ +WINDOWS\system32\cmd.exe' IPC::Run 0000 0123-------- [#1(44744)]: kid 1 to read 0 from SCALAR IPC::Run 0000 01234------- [#1(44744)]: win32 port = 2048 IPC::Run 0000 012345------ [#1(44744)]: accept()ing on port 2048 IPC::Run 0000 0123456----- [#1(44744)]: win32 _socket = ( 6, 5 ) on po +rt 2048 IPC::Run 0000 0123-56----- [#1(44744)]: PUMP_SOCKET_HANDLE = 5 IPC::Run 0000 01234567---- [#1(44744)]: CHILD_HANDLE = 4 IPC::Run 0000 01234567---- [#1(44744)]: PUMP_PIPE_HANDLE = 7 IPC::Run 0000 01234567---- [#1(44744)]: disabling inheritance of 6 IPC::Run 0000 01234567---- [#1(44744)]: disabling inheritance of 5 IPC::Run 0000 01234567---- [#1(44744)]: disabling inheritance of 7 IPC::Run 0000 01234567---- [#1(44744)]: disabling inheritance of 4 IPC::Run 0000 01234567---- [#1(44744)]: pumper stdin = 5 IPC::Run 0000 01234567---- [#1(44744)]: pumper stdout = 7 IPC::Run 0000 01234567---- [#1(44744)]: enabling inheritance of 5 IPC::Run 0000 01234567---- [#1(44744)]: enabling inheritance of 7 IPC::Run 0000 01234567---- [#1(44744)]: enabling inheritance of 3 IPC::Run 0000 01234567---- [#1(44744)]: pump cmd line: "C:\Perl\bin\pe +rl.exe" "-IC:\Program Files\ActiveState Perl Dev Kit 6.0\lib\" "-IC:/ +Perl/lib" " -IC:/Perl/site/lib" "-I." -MIPC::Run::Win32Pump -e 1 1852 1876 15 0 44 +744 1123101917 999 "4<pump<6" IPC::Run 0000 01234-6----- [#1(44744)]: _spawn_pumper pid = 43144 IPC::Run 0000 01234-6----- [#1(44744)]: win32_fake_pipe = ( 6, 4 ) IPC::Run 0000 01234-6----- [#1(44744)]: kid 1 to write 1 to a pipe IPC +::Run opens and returns IPC::Run 0000 0123456----- [#1(44744)]: win32 port = 2049 IPC::Run 0000 01234567---- [#1(44744)]: accept()ing on port 2049 IPC::Run 0000 012345678--- [#1(44744)]: win32 _socket = ( 8, 7 ) on po +rt 2049 IPC::Run 0000 01234-678--- [#1(44744)]: PUMP_SOCKET_HANDLE = 7 IPC::Run 0000 0123456789-- [#1(44744)]: CHILD_HANDLE = 9 IPC::Run 0000 0123456789-- [#1(44744)]: PUMP_PIPE_HANDLE = 5 IPC::Run 0000 0123456789-- [#1(44744)]: disabling inheritance of 8 IPC::Run 0000 0123456789-- [#1(44744)]: disabling inheritance of 7 IPC::Run 0000 0123456789-- [#1(44744)]: disabling inheritance of 5 IPC::Run 0000 0123456789-- [#1(44744)]: disabling inheritance of 9 IPC::Run 0000 0123456789-- [#1(44744)]: pumper stdin = 5 IPC::Run 0000 0123456789-- [#1(44744)]: pumper stdout = 7 IPC::Run 0000 0123456789-- [#1(44744)]: enabling inheritance of 5 IPC::Run 0000 0123456789-- [#1(44744)]: enabling inheritance of 7 IPC::Run 0000 0123456789-- [#1(44744)]: enabling inheritance of 3 IPC::Run 0000 0123456789-- [#1(44744)]: pump cmd line: "C:\Perl\bin\pe +rl.exe" "-IC:\Program Files\ActiveState Perl Dev Kit 6.0\lib\" "-IC:/ +Perl/lib" " -IC:/Perl/site/lib" "-I." -MIPC::Run::Win32Pump -e 1 1808 1876 15 0 44 +744 1123101917 999 "9>pump>8" IPC::Run 0000 01234-6-89-- [#1(44744)]: _spawn_pumper pid = 43888 IPC::Run 0000 01234-6-89-- [#1(44744)]: win32_fake_pipe = ( 8, 9 ) IPC::Run 0001 01234-6-89-- [#1(44744)]: caller will read from 8 IPC::Run 0001 01234-6-89-- [#1(44744)]: kid 1 to write 2 to '1' (write + only, create, truncate) IPC::Run 0001 01234-6-89-- [#1(44744)]: O_RDONLY=0x00 O_WRONLY=0x01 O_ +RDWR=0x02 O_TRUNC=0x200 O_CREAT=0x100 O_APPEND=0x08 IPC::Run 0001 0123456-89-- [#1(44744)]: open( 1, 0x301 ) = 5 IPC::Run 0001 0123456-89-- [#1(44744)]: kid 1[]'s 0 is my 6 IPC::Run 0001 0123456-89-- [#1(44744)]: child: `cmd.exe '/C' 'echo hel +lo'` IPC::Run 0001 0123456-89-- [#1(44744)]: spawning 'C:\WINDOWS\system32\ +cmd.exe' '/C' 'echo hello' IPC::Run 0001 0123456-89-- [#1(44744)]: disabling inheritance of 3 IPC::Run 0001 0123456-89-- [#1(44744)]: disabling inheritance of 6 IPC::Run 0001 0123456789-- [#1(44744)]: dup( 0 ) = 7 IPC::Run 0001 0123456789-- [#1(44744)]: disabling inheritance of 7 IPC::Run 0001 0123456789-- [#1(44744)]: disabling inheritance of 7 IPC::Run 0001 0123456789-- [#1(44744)]: moving 4 to kid's 0 IPC::Run 0001 0123456789-- [#1(44744)]: dup2( 4, 0 ) = 0 IPC::Run 0001 0123456789-- [#1(44744)]: disabling inheritance of 4 IPC::Run 0001 01234567890- [#1(44744)]: dup( 1 ) = 10 IPC::Run 0001 01234567890- [#1(44744)]: disabling inheritance of 10 IPC::Run 0001 01234567890- [#1(44744)]: disabling inheritance of 10 IPC::Run 0001 01234567890- [#1(44744)]: moving 9 to kid's 1 IPC::Run 0001 01234567890- [#1(44744)]: dup2( 9, 1 ) = 0 IPC::Run 0001 01234567890- [#1(44744)]: disabling inheritance of 9 IPC::Run 0001 012345678901 [#1(44744)]: dup( 2 ) = 11 IPC::Run 0001 012345678901 [#1(44744)]: disabling inheritance of 11 IPC::Run 0001 012345678901 [#1(44744)]: disabling inheritance of 11 IPC::Run 0001 012345678901 [#1(44744)]: moving 5 to kid's 2 IPC::Run 0001 012345678901 [#1(44744)]: dup2( 5, 2 ) = 0 IPC::Run 0001 012345678901 [#1(44744)]: disabling inheritance of 5 IPC::Run 0001 012345678901 [#1(44744)]: cmd line: C:\WINDOWS\system32\ +cmd.exe /C "echo hello" IPC::Run 0001 012345678901 [#1(44744)]: dup2( 10, 1 ) = 0 IPC::Run 0001 0123456789-1 [#1(44744)]: close( 10 ) = 0 IPC::Run 0001 0123456789-1 [#1(44744)]: dup2( 7, 0 ) = 0 IPC::Run 0001 0123456-89-1 [#1(44744)]: close( 7 ) = 0 IPC::Run 0001 0123456-89-1 [#1(44744)]: dup2( 11, 2 ) = 0 IPC::Run 0001 0123456-89-- [#1(44744)]: close( 11 ) = 0 IPC::Run 0001 0123456-89-- [#1(44744)]: spawn() = 43092 IPC::Run 0001 0123-56-89-- [#1(44744)]: close( 4 ) = 0 IPC::Run 0001 0123-56-8--- [#1(44744)]: close( 9 ) = 0 IPC::Run 0001 0123--6-8--- [#1(44744)]: close( 5 ) = 0
Any ideas?
Mark
holli added readmore tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl/Tk IPC::Run and filevent fun on win32!
by zentara (Cardinal) on Aug 04, 2005 at 11:45 UTC |