Provide two C functions, say() and sayf(), and have them forward the strings on to your hook. No need to force say() to use Perl's built-in print so it can find STDOUT tied and call the tie code to eventually get the data to your code.

Also, I'm not sure why you think the process boundaries need to be divided up the way you envision. I'd just have one very simple separate process that just does the screen updates. Keep everything else together like you already have it.

I would have thought that the "GUI" part of your creation would have already forced threads much more than this little "redirect output" thing.

Most GUIs have a widget or such that will update with text when it becomes available. So imagine just redirecting STDOUT to the 'in' side of a pipe and telling such a widget to display whatever text comes from the 'out' side of the pipe.

That might not work by itself because a pipe will only buffer up a fairly small amount before trying to write more will block waiting for some of the buffered data to be read. And your widget might not get access to the CPU until the 'write' finishes. That is, deadlock.

But a responsive GUI app needs to deal with this type of thing anyway so just the "pipe to yourself" might work. But if it doesn't, all you need to add is a buffering bit pump process.

Or, simplest of all, just direct STDOUT to a temporary file and have the widget monitor the file for new text.

- tye        


In reply to Re: Capturing XS printf output with a tied filehandle (lots) by tye
in thread Capturing XS printf output with a tied filehandle by run4flat

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.