summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@chalmers.se>2010-09-23 08:23:43 +0200
committerGuilhem Moulin <guilhem.moulin@chalmers.se>2010-09-23 08:23:43 +0200
commit7c2073be62cd72779291943ead8beed5b7876d36 (patch)
tree044f6cdd6ef86a68c69b71398318385f487b7768
parent807eba001ee768e6156423213080dc0ffe50695e (diff)
waitpids
-rwxr-xr-xpdftool.pl41
1 files changed, 22 insertions, 19 deletions
diff --git a/pdftool.pl b/pdftool.pl
index 7e64d40..55b13bb 100755
--- a/pdftool.pl
+++ b/pdftool.pl
@@ -100,6 +100,9 @@ my @auxfiles;
my @auxfds;
+# Pids, to waid for
+my @pids;
+
if ($filename eq "-") {
# Need to copy the whole input to an auxiliary file, since
# conversion from pdf to ps requires random access to the data
@@ -126,14 +129,18 @@ if ($filetype eq "PDF") {
# open2 PSFILE, '<&STDIN', "$pdf2ps $filename -"
or die "Error with `$pdf2ps $filename -'";
} else {
- open *PSFILE, '<', "$filename"
+ open *PSFILE, "$filename"
or die "Can't open `$filename'";
}
push @auxfds, fileno PSFILE;
+my $pid;
+
# Resize file to our papersize
-open2 *PSRESIZE, "<&PSFILE", "$psresize", "-p$papersize"
- or die "Error with `$psresize -p$papersize'";
+$pid = open2 *PSRESIZE, "<&PSFILE", "$psresize", "-p$papersize"
+ or die "Error with `$psresize -p$papersize'";
+#push @auxfds, fileno PSRESIZE;
+push @pids, $pid;
# pscrop
@@ -144,33 +151,29 @@ open2 *PSRESIZE, "<&PSFILE", "$psresize", "-p$papersize"
# psnup
# TODO: sometimes unecessary
-open2 *PSNUP, "<&PSBOOK", "$psnup", "-p$papersize", "-m$mnup", "-$nup"
- or die "Error with `$psnup -p$papersize -m$mnup -$nup'";
+$pid = open2 *PSNUP, "<&PSBOOK", "$psnup", "-p$papersize", "-m$mnup", "-$nup"
+ or die "Error with `$psnup -p$papersize -m$mnup -$nup'";
+#push @auxfds, fileno PSNUP;
+push @pids, $pid;
# TODO: not always stdout
-open2 ">&STDOUT", "<&PSNUP", "$ps2pdf -sPAPERSIZE=$papersize - -"
- or die "Error with `$ps2pdf -sPAPERSIZE=$papersize - -'";
-
-#flush;
-print STDERR "ok\n";
-close STDIN;
-close STDOUT;
+$pid = open2 ">&STDOUT", "<&PSNUP", "$ps2pdf -sPAPERSIZE=$papersize - -"
+ or die "Error with `$ps2pdf -sPAPERSIZE=$papersize - -'";
+push @pids, $pid;
+# avoid zombies
+map {waitpid $_, 0} @pids;
-close PSNUP;
-close PSBOOK;
-close PSCROP;
-close PSRESIZE;
-close PSFILE;
-
# close auxiliary filehandles
-#map {close $_} @auxfds;
+map {close $_} @auxfds;
+
# delete auxiliary files
unlink @auxfiles;
+
#TODO: better do forget stdin, I guess
#if ($filename eq "-" && $filetype eq "PDF") {
#}