Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: IO::Socket:SSL and Net::Server STDOUT redirection

by Loops (Curate)
on Nov 17, 2014 at 19:21 UTC ( #1107461=note: print w/replies, xml ) Need Help??


in reply to IO::Socket:SSL and Net::Server STDOUT redirection

McA got to the heart of the problem already, although I'm not sure if the same solution can be applied with Net::Server. It uses Tie::Handle to capture STDOUT, which obviously wont be respected by any forked process. However, you could use IPC::Run to capture the output instead. The following works:

package NetServer; use base qw(Net::Server::Fork); use IPC::Run; sub SSL_key_file { "key.pem" } sub SSL_cert_file { "cert.pem" } sub process_request { my $command = [ 'echo', '==== System Command Successful' ]; IPC::Run::run($command, '>', sub { print shift }); } NetServer->run(proto => 'ssleay', port=>12345);

And actually in the simple case, IPC::Run doesn't buy you much over just:

print qx( /usr/bin/echo ==== System Command Successful );

But to be clear, the IPC::Run version is better when executing a long running child, since it will asynchronously capture and forward output. The "qx" version waits until the child completes before forwarding the output.

Replies are listed 'Best First'.
Re^2: IO::Socket:SSL and Net::Server STDOUT redirection
by Zucan (Beadle) on Nov 17, 2014 at 21:51 UTC

    This worked pretty good too. Thank you!

    The distinction between qx() and the IPC::Run version was also nicely explained. I appreciate it!

    Zucan

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1107461]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2021-04-14 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?