Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I'm running Perl 5.8.2 under Windows. I'm calling the "psftp" command from Perl using the backquotes to collect the command output in a variable to keep the output from going to a command prompt screen. The following line of code I'm using puts most of the output into the variable: $output = `psftp $user -pw $server -b $ftpCommands`; However, the text: Using username "ftpuser". is still displayed on the screen. Does anyone have any suggestions as to why that particular message isn't redirected to the variable?
  • Comment on Suppressing backquote call display out - psftp - windows

Replies are listed 'Best First'.
Re: Suppressing backquote call display out - psftp - windows
by kennethk (Abbot) on Apr 15, 2009 at 18:16 UTC

    Please read Writeup Formatting Tips. In particular, using <code> tags to surround code, though it is less important in this case.

    I suspect the displayed text is being output to STDERR and not STDOUT. You should be able to redirect it to STDOUT with 2>&1, so your entire command becomes

    $output = `psftp $user -pw $server -b $ftpCommands 2>&1`;

      Yeah, using 2>&1 worked perfectly. Thank you!! Sorry about not using the <code> tags. Thanks again.