in reply to (solved) Redirect Shell Launch to perl script

Hi delpi,

Without knowing anything about the server, it's a little difficult to give a good answer, also you don't tell us how you know your Perl script isn't working - e.g. you could have it write debug output to a separate logfile.

Anyway, I have two ideas. First, if you can get the server to write its output to a log file which you can then view live with tail, you can do the same with Perl, with the module File::Tail. That has the advantage of decoupling the two processes, at the expense of a small bit of performance.

Second, you could try invoking the server with something like IPC::Run, which can communicate with the subprocess interactively. The disadvantage is that now the server is a subprocess of the Perl script, which might not work if, for example, the server tries to detach itself and go into the background (daemonize). Anyway, a simple example:

use IPC::Run qw/run/; run ['/path/to/server'], \undef, sub { my $in = shift; chomp($in); print "<<$in>>\n"; };

However, depending on how the server is implemented, this solution may still suffer from buffering.

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^2: Redirect Shell Launch to perl script
by delpi (Novice) on Nov 27, 2016 at 18:22 UTC
    I'll have to explore that for another project I'm working on. Thanks.