Thread Wie kann man eine Batch mit Hilfe von system() parallel aufrufen?? (9 answers)
Opened by crojay at 2011-09-23 15:16

crojay
 2011-09-23 17:52
#152645 #152645
User since
2011-03-08
81 Artikel
BenutzerIn
[default_avatar]
Mein Fehler hab das falsche Array verwendet...


So läuft das Skript, auf den ersten Blick auch parallel
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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 @systemCall,\@gswinCall;
        
    
    }
    
    
    foreach my $convertCall(@systemCall){
          print "start-------------------------\n";
          print "---->".join(" ", @{$convertCall}) ."<-----\n";
          print "end-------------------------\n";
    }
    
    
     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";
     
    
    
}

View full thread Wie kann man eine Batch mit Hilfe von system() parallel aufrufen??