I have a web application that I use to spawn another program at the user's request. I would like to be able to display a progress bar for the user in the web app...but am a bit confused on how to do that. I have most of the pieces, but can't seem to get it all together. My spawned process (currently) spits out the number of lines processed on a periodic basis to STDOUT (but would prefer this to be more elegant IPC), which I would like to capture while the external program is running and send that back to the user interface via a Websocket connection as a percent complete in a javascript progress bar.

Currently, the external program writes its progress to STDOUT, I have a javascript widget that will accept the progress percentage, I have the web socket connection. What I don't have is a method for executing the external program (I am assuming IPC::Open3, IPC::Run3 or similar) and watching the progress within a loop (while?) until the program terminates (normally or not...I can handle abnormal exits already). During the loop execution, I would like to send the percentage of completion as it is received with a threshold set for the minimum interval between updates (already can handle the update frequency).

Any help or suggestions would be greatly appreciated...I guess that my first attempt at this would be to simply watch STDOUT use a regex to grab the formatted progress updates...but how do I break out of the loop? A not so sophisticated approach is to write "FINISHED" to STDOUT and watch for that...but that seems a bit unsophisticated and prone to errors.


In reply to capture periodic updates from external program by mabossert

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.