any '/run' => sub { my $dest = '/var/local/testp/public/results'; my ($fh,$filename) = tempfile(); my $command = "/usr/bin/R -q --slave --vanilla < /var/local/testp/data/code.R > $filename && mv $filename $dest/${filename}\.html"; my $proc1 = Proc::Background->new($command); my $htmlfile = "$dest" . "$filename" . '.html'; open (my $hfh,">>",$htmlfile) or die "can\'t open file $htmlfile: $!\n"; print $hfh ""; print $hfh "waiting for \ results"; close $hfh; unlink ($fh); return redirect "/results/${filename}\.html"; };