in reply to Handling STDERR when using Net::OpenSSH

Add master_stderr_discard => 1 to the constructor call:
my $ssh = Net::OpenSSH->new($remote_host, ssh_cmd => '/usr/local/bin/ssh', user => $user, password => $pass, master_stderr_discard => 1);

Replies are listed 'Best First'.
Re^2: Handling STDERR when using Net::OpenSSH
by sittingbull (Initiate) on Oct 14, 2010 at 14:09 UTC
    Salva you are the best, thanks.

    And me, I am an idiot for not reading the API doc before posting.

    Max
Re^2: Handling STDERR when using Net::OpenSSH
by Anonymous Monk on May 15, 2018 at 07:35 UTC

    Hi, I know I'm replying to a bit of an old thread here, but I'm at a loss.

    I'm trying to use Net::OpenSSH 0.7.0 within an apache fastCGI script (not recommended, I know!).

    No matter what I do, I can't get it to run due to fastCGI messing with the standard filehandles.

    I get either:

    child process STDIN is not a real system file handle. or Operation 'OPEN' not supported on FCGI::Stream handle

    I've tried various combinations of :

    default_stdin_discard => 1, default_stdout_discard => 1, default_stderr_discard => 1, master_stderr_fh => $stderr_fh, master_stdout_fh => $stdout_fh,

    I've tried reopening STDIN from /dev/null locally.

    I'm pulling my hair out here.

    Any hints?

      Can you please describe (or show relevant code) of your setup in a bit more detail just so we can understand your situation better?

      I think your setup is something like the following:

      local machine remote machine script Net::OpenSSH fastCGI script

      ... and you want to run the fastCGI script and get its output?

      Maybe you can also show us how you're starting the fastCGI script exactly. Maybe FastCGI is happier with having actual filehandles (with inodes), or it wants a /dev/tty or a domain socket to interact with, instead what Net::OpenSSH provides directly.

      A nasty alternative could be to set up just enough of Apache (or another FastCGI environment using Net::FastCGI or whatever), and then access the script via http...

        I mean I have an apache application, using CGI::Fast (which uses FCGI). This application is working happily.

        Now I'm trying to add a request handler that upon receiving a request via apache, it will attempt to use Net::OpenSSH to connect to a remote host

        The issue is FCGI / CGI::Fast have captured and redirected the STDIN/STDOUT/STDERR filehandles and Net::OpenSSH dies when I try to create a new Net::OpenSSH object

        Abbreviated code below

        use CGI::Fast; while (my $r = CGI::Fast->new) { open my $stderr_fh, '>', 'some_file'; open my $stdin_fh, '<', '/dev/null'; open my $stdout_fh, '>', 'some_other_file'; my %options = ( batch_mode => 1, timeout => 10, kill_ssh_on_timeout => 1, default_stdout_discard => 1, default_stderr_discard => 1, master_stderr_fh => $stderr_fh, master_stdout_fh => $stdout_fh, ); my $ssh = Net::OpenSSH->new('test@192.168.0.123', %options); }

        The errors invariably occur inside the Net::OpenSSH->new() call