Dear Monks,
I am looking for a kind advise for the following problem:
I need to run an external command which can take long time to run ( minutes or even hours ) I use for that Proc::Background.
Now I need a way to tell the browser to refresh the page until the result is ready, Or implement a way to check that process is still running.
That's what I managed to do for now and to be honest it looks very ugly:
It doesn't matter in general but I use perl dancer for my little web project.

any '/run' => sub { my $dest = '/var/local/testp/public/results'; my ($fh,$filename) = tempfile(); my $command = "/usr/bin/R -q --slave --vanilla < /var/local/te +stp/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 $htmlfi +le: $!\n"; print $hfh "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5; URL=/res +ults/${filename}\.html\">"; print $hfh "waiting for \<a href=\"/results/${filename}\.html\ +"> results</a>"; close $hfh; unlink ($fh); return redirect "/results/${filename}\.html"; };
so basically I create an empty static html page which refreshes itself each 5 seconds
and when the process is finished I simply overwrite the this page with the result.
it works, but I think there is a better and more elegant way to do it.

Thank you.

In reply to cgi,wait for long running external prog by noname

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.