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:42
#152644 #152644
User since
2011-03-08
81 Artikel
BenutzerIn
[default_avatar]
HAllo,

danke erstmal für den Tipp.


Ich habe mich nun für den FOrkManager entschieden und bekomme es noch nicht so zum laufen. ALso was mein Skript machen sollte ist.

1. Die Postscript Dateien ermitteln
2. Einen Ghostscript Command Line Befehl zusammen bauen pro Ps-Datei
3. Nun sollten die aus 2. ermittelten Calls Parallel aufgerufen werden.

Leider geht mein PC beim Aufruf meines Scripts in die Knie und Padre meldet ein Out of Memory. Ich habe aber das ganze nur mit 10 PS Dateien versucht und die werden auch auch nicht erstellt.

Wo liegt denn mein (Denk) Fehler??


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
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";
    
    
    
    
}

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