in reply to Script hangs when executing command over ssh

One oddity I ran into, too long ago to remember the details, was an issue with the way STDERRwas buffered. You may be bumping into that; I wish I remembered more about the problem. Something about STDERRbeing held until the end of the run and then released? Sorry, it's been too long.

One thing I'm noticing is that your command line is redirecting STDOUTto STDERRusing the 1>&2technique. However, in your invocation, you seem to be wishing to capture $stdoutand $stderrseparately.

Perhaps you'd have more luck getting rid of the command redirect and simply capturing the data raw with your call to $ssh->cmd?

my ($stdout, $stderr, $exit) = $ssh->cmd('cat /tmp/a');

Replies are listed 'Best First'.
Re^2: Script hangs when executing command over ssh
by eg2014 (Initiate) on Jun 18, 2015 at 17:00 UTC

    Thank you for your reply. Yes perhaps it does have to do with the STDERR buffering, and it seems to be at about 32K. Do I need to increase that buffer somehow?

    The actual program I am running is outputting to STDERR (and STDOUT) and I have no control over that output. I just gave the above code as an example of the more complicated one.

      If there's a way to work with the buffer, hopefully a more Unix/Linux-oriented Monk will come along with a suggestion. However, I don't think you understood my point about getting rid of the piping.

      Try removing the 1>&2from your command, and see if the problem goes away.

        I understand your point regarding the output redirection. Removing 1>&2 from the command does get rid of the problem in this specific example.

        However the actual program is being run like  $ssh->cmd('/bin/a'); and it writes some output to STDERR, and unfortunately I do not have any control over that. Thank you