sub downloadcsv : Runmode { my $self = shift; if (my $pid = fork) { # parent does this return $self->redirect("/myapp.pl/csv_status"); } elsif (defined $pid) { # child does this close STDOUT; close STDERR; open STDERR, ">&=1"; my $id = $self->session->id(); my $cmd = "$CFG{'PATH'}/make_csv.pl"; exec "$cmd", "$id"; die "can't do exec: $!"; } else { die "cannot fork: $!"; } }