It does not surprise me that mixing Capture::Tiny with threading doesn't work well. Indeed, it would surprise me if it did. The standard file handles are process-global entities and thus shared by all the threads in the process.
If you want your threads to all write to them concurrently, then you would need to use locking to ensure that the output from different threads didn't become mixed up and corrupted. That's relatively trivial to do:
use threads::shared; my $sem : shared; sub tprint { lock $sem; print @_; } sub twarn { lock $sem; warn @_; }
But attempting to add Capture::Tiny into the mix simply isn't going to work as it uses fork to perform its work, and is completely oblivious to threading.
As for an alternative; I cannot work out from your question or your toy code what it is that you're actually trying to achieve.
But, if you can describe what it is that you need to do; rather than how you are currently trying to do "it"; then I might be able to help.
In reply to Re: capturing output of system call inside a thread
by BrowserUk
in thread capturing output of system call inside a thread
by that_guy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |