Problem with Storable on Windows
am 04.07.2005 13:20:08 von dfg778I'm trying to use Storable in conjunction with IPC::Open3 in order to
send complex data structures between the parent and child processes.
Unfortunately, although this seems to work a treat under Linux (Fedora
Core 4), it doesn't seem to work on Windows, returning the following
message:
Magic number checking on storable file failed at blib\lib\Storable.pm
(autosplit into blib\lib\auto\Storable\fd_retrieve.al) line 323, at
D:\Data\Perl\DBAsyncWorker.pl line 13
Here's my code:
Caller:
#!/usr/bin/perl
use Storable qw(nstore_fd freeze) ;
use IPC::Open3 ;
use IO::Handle ;
autoflush STDOUT ;
print "Caller starting\n" ;
$Storable::Deparse = 1 ;
%parms = ( data_source => 'DBI:Pg:dbname=matthew',
userid => 'matthew',
password => 'vishnu',
statement => 'select * from test_table') ;
$command = 'DBAsyncWorker.pl' ;
print "About to call worker\n" ;
$pid = open3($wtr,$rdr,$err,$command) ;
# This line added for Windows
binmode $wtr ;
print "Worker started\n" ;
while(($line = <$rdr>) !~ 'End') {
if ($line =~ /START/) {
print "Received start command\n" ;
nstore_fd \%parms, $wtr ;
}
else {
print $line ;
}
}
Worker:
#!/usr/bin/perl
use DBI ;
use Data::Dumper ;
use IO::Handle ;
use Storable qw(fd_retrieve thaw) ;
$Storable::Eval = 1 ;
autoflush STDOUT ;
# This line added for Windows
binmode STDIN ;
print "START\n";
$parm_ref = fd_retrieve(\*STDIN) ;
print "Retrieved parm reference\n",Dumper($parm_ref) ;
print "Userid = ",$parm_ref->{userid},"\n" ;
print "Password = ",$parm_ref->{password},"\n" ;
print "Statement = ",$parm_ref->{statement},"\n" ;
print "End\n" ;
Here's what I've tried, without luck:
* Using store_fd instead of nstore_fd
* Using freeze in the caller, printing the frozen value to $wtr, and
then reading it on the worker using sysread and using thaw
Freeze'ing and thaw'ing within a single program works fine, it's just
when I send it over a file handle that the problem occurs.
Does anybody have any ideas ?