+# shells don't do well with handling exit values from pipelines, so we emulate
+# a pipeline in perl, in such a way that we can combine both exit statuses in a
+# kind of logical "OR".
+@PERL@ - $amlibexecdir/planner$SUF $amlibexecdir/driver$SUF $conf $date_starttime "$@" <<'EOPERL'
+use IPC::Open3;
+use POSIX qw(WIFEXITED WEXITSTATUS);
+my ($planner, $driver, $conf, $date_starttime, @args) = @ARGV;
+
+open3("</dev/null", \*PIPE, ">&STDERR", $planner, $conf, '--starttime', $date_starttime, @args)
+ or die "Could not exec $planner: $!";
+open3("<&PIPE", ">&STDOUT", ">&STDERR", $driver, $conf, @args)
+ or die "Could not exec $driver: $!";
+
+my $first_bad_exit = 0;
+for (my $i = 0; $i < 2; $i++) {
+ my $dead = wait();
+ die("Error waiting: $!") if ($dead <= 0);
+ my $exit = WIFEXITED($?)? WEXITSTATUS($?) : 1;
+ $first_bad_exit = $exit if ($exit && !$first_bad_exit)
+}
+exit $first_bad_exit;
+EOPERL