use LWP::Simple; use Parallel::ForkManager; use File::Basename; use strict; my @gswinCommand = qw(-q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite);#$pdfCompatibility); my $gsBin = "c:\\Program Files (x86)\\gs\\gs8.70\\bin\\gswin32c.exe"; my $ps_input = "f:\\tmp\\thread_test\\ps"; my $pdf_output = "f:\\tmp\\thread_test\\pdf"; print join(" ",@gswinCommand) ."\n"; if (-e $gsBin){ print "found ghostview\n"; my @psFiles = glob("$ps_input\\*.ps"); my @systemCall; foreach my $psFile (@psFiles){ my($filename, $directories, $suffix) = fileparse($psFile); my $pdfFileName = $pdf_output ."\\". substr($filename,0,rindex($filename,".")) . ".pdf"; my $outputcmd = "-sOutputFile=" . $pdfFileName; my @gswinCall = ($gsBin,@gswinCommand, $outputcmd, $psFile); #print "-->" . join(" ",@gswinCall) . "<---\n"; #print "psFile = $psFile | pdf = $pdfFileName\n"; #my $result = system(@gswinCall); #print "result of last system call was $result\n"; push @psFiles,@gswinCall } my $pm = new Parallel::ForkManager(3); foreach my $convertCall (@systemCall){ $pm->start and next; my $result = system(@{$convertCall}); print "result of last system call was $result\n"; $pm->finish; # do the exit in the child process } $pm->wait_all_children; print "all processes finished\n"; }