|Just another Perl shrine|
Win32: Redirect STDOUT to socketby repellent (Priest)
|on Feb 09, 2009 at 06:51 UTC||Need Help??|
repellent has asked for the
wisdom of the Perl Monks concerning the following question:
Dear monks, I'm having trouble redirecting STDOUT to a socket. I'm using ActiveState Perl v5.10.0 built for MSWin32-x86-multi-thread.
When $bug_on = 0; this is the output:
When $bug_on = 1; I expect to see:
but it just stalls (on the readline?). I've seen howto redirect STDOUT to $socket but can't seem to figure out what's wrong. I'm stuck. Thanks in advance!
UPDATE #1: Thanks to all who have replied. I updated the code to add in 2 lines of code, adding the suggestion from ikegami.
Now when $bug_on = 1; I get:
At this point, after what BrowserUk mentioned, I'm merely curious as to what Perl is really doing internally.
From observation, I think that the STDOUT redirection is not persistent into the exec, and that exec resets STDOUT to the usual because it doesn't know any better. Is this assumption correct?
If so, then how does Perl process backticks to return the STDOUT of a process? All I really want is to manually capture STDOUT of another process without qx() (for my education :). No Tim Toady for backticks in Win32?
UPDATE #2: Big thanks to BrowserUk! So I dived a little deeper and I think I'm drowning badly in Win32 waters... I tried using Win32::Process::Create to spawn a process that will inherit parent filehandles, but the output is still the same as before:
I don't think the filehandles are inherited. Any ideas, anyone?