in reply to Speeding up external command execution
Apart from the timing issues, the logic you're using to build the command line is strange. I would have done it something like this:
My version should yield the same behavior as yours, but if, instead of using "master*.svg", you were to use the actual list of file names (that is, the names of the svg files that were just created previously in your script), like this:my $pathstr = join( '', $outputfiles, $invoice_data_ref{actual_invoice +_id} ); my @cmdargs = ( 'java', '-jar', '/var/ww/helper_code/svg2pdf.jar', "$pathstr/master*.svg", "$pathstr/master.pdf" ); print join( ' ', 'command_str:', @cmdargs ), "\n"; # optional - just +to check $report_failure = system( @cmdargs );
then the method of execution will be slightly different. If you haven't read perldoc -f system, you might find that interesting.my @svg_names = ( qw/master01 master02 .../; # or whatever those names + are # … create those files ... my $pathstr = join( '', $outputfiles, $invoice_data_ref{actual_invoice +_id} ); my @cmdargs = qw/java -jar /var/ww/helper_code/svg2pdf.jar/; push @cmdargs, "$pathstr/$_.svg" for ( @svg_names ); push @cmdargs, "$pathstr/master.pdf";
I expect that after you generate all those "fairly complicated SVGs", you close those file handles (i.e. make sure all the output has been flushed) before doing the system call. If those file handles are still open, perl will flush them for you when you do the system call, which might add a bit of delay.
Your description suggests that the system call is only being done once; if you were doing a lot of similar system calls in some sort of loop, then one possible cause of delay would be the extra overhead of invoking and cleaning up after a subshell on each iteration; one way to get around that (on a *n*x system) would be:
But that's probably not relevant here.open( SH, '|-', '/bin/sh' ) or die "Can't open a shell: $!"; for my $iterator ( @whatever_set ) { print SH "command line…\n" } close SH;
|
|---|