in reply to Re: Start windows .exe
in thread Start windows .exe

Maybe you can help me a little further: I have the following code that just listens for files in the in directory. When it finds a file in the "in" directory it forks and then copies the file to the "out" directory where a system call to FTP the file takes place.

My problem is that it forks just fine and it starts to FTP the files using the FTP_Client.exe program, however I get all these error messages ("Free to wrong pool ... C:/Perl/lib/IO/Dir.pm") before the program crashes.

Can anyone see what I am doing wrong? I am new with PERL.

THanks,
Andrew
My PERL code:
use IO; use File::Copy; use Fcntl ':mode'; use warnings; use Net::ftp; use Net::Ping; use Time::localtime; use POSIX ":sys_wait_h"; system ("color 1f"); my $indir = ".\\in"; my $outdir = ".\\out"; my $expr = "*.*"; my $RemFile = "*.*"; my $d; if ( ! -e $indir ){ print "$indir does not exist, attempting to create\n"; mkdir ($indir, 0777 ) or die "Can not create $indir: $!"; } if ( ! -e $outdir ) { print "$outdir does not exist, attempting to create\n"; mkdir ($outdir, 0777 ) or die "Can not create $outdir: $!"; } while(1){ $d = new IO::Dir "$indir"; tie %dir, IO::Dir, "$indir"; foreach (keys %dir) { #if the expr is found in the InDir it will be FTP'd if( ! S_ISDIR($dir{$_}->mode) && /^$expr/ ) { if($pid = fork){ waitpid(-1, &WNOHANG); } else{ $RemFile = $_; #move the file to the out directory move( "$indir/$_", "$_"); #chdir ($outdir); print "Starting to FTP: $_\n"; system("FTP_Client.exe $_"); print "Finished: $_ \n\n"; move( "$_", "$outdir/$_"); exit(1); } } #sleep(5); } }

Replies are listed 'Best First'.
Re^3: Start windows .exe
by NateTut (Deacon) on Jul 14, 2005 at 12:55 UTC
    Have you been able to pinpoint which line(s) are causing the errors? Also I would recommend using "use strict;"
Re^3: Start windows .exe
by NateTut (Deacon) on Jul 14, 2005 at 13:14 UTC
    Here's a version that passes "use strict;" I declared a couple of variables and put 's around IO::Dir in the tie command. Also "use IO;" is depracted so I changed that to "use IO::Dir;". I can't give it a good test as I can't replicate your environment, but I hope this helps.
    use IO::Dir; use File::Copy; use Fcntl ':mode'; use strict; use warnings; use Net::ftp; use Net::Ping; use Time::localtime; use POSIX ":sys_wait_h"; system ("color 1f"); my $indir = ".\\in"; my $outdir = ".\\out"; my $expr = "*.*"; my $RemFile = "*.*"; my $d; if ( ! -e $indir ){ print "$indir does not exist, attempting to create\n"; mkdir ($indir, 0777 ) or die "Can not create $indir: $!"; } if ( ! -e $outdir ) { print "$outdir does not exist, attempting to create\n"; mkdir ($outdir, 0777 ) or die "Can not create $outdir: $!"; } while(1){ $d = new IO::Dir "$indir"; my %dir; tie %dir, 'IO::Dir', "$indir"; foreach (keys %dir) { #if the expr is found in the InDir it will be FTP'd if( ! S_ISDIR($dir{$_}->mode) && /^$expr/ ) { my $pid; if($pid = fork){ waitpid(-1, &WNOHANG); } else{ $RemFile = $_; #move the file to the out directory move( "$indir/$_", "$_"); #chdir ($outdir); print "Starting to FTP: $_\n"; system("FTP_Client.exe $_"); print "Finished: $_ \n\n"; move( "$_", "$outdir/$_"); exit(1); } } #sleep(5); } }