in reply to Re: Perl die after executing external program
in thread Perl die after executing external program

Yes, I'm using root account for executing this perl script.
  • Comment on Re^2: Perl die after executing external program

Replies are listed 'Best First'.
Re^3: Perl die after executing external program
by mr_mischief (Monsignor) on Apr 29, 2011 at 12:51 UTC
    I see you replied to Re: Perl die after executing external program after I posted Re: Perl die after executing external program but did you bother to read what I typed? You're already capturing STDOUT of the process. You also need to capture STDERR, because that's where the output you want goes.

    Yes, it really is that simple. Differences in account permissions are always a relatively good guess about differences in how programs operate, but a good guess is still a guess. Which file descriptor lftp uses for output doesn't change depending on which account is running the program. Which one you need to capture does change depending on which one is being written to in the executed program.

    2>&1 is your friend.

      Yes, I did tried to capture the STDERR but nothing written there. Empty.

        That's odd. This code works for me:

        my $CLIENT = "lftp"; my $connectionString = "" . $CLIENT . " -d -f bar 2>&1"; my $result = `$connectionString` || die "\nERROR running $CLIENT: $!"; print $result;

        The return won't work because this isn't part of a subroutine, but you should get an error about that specifically if this is really the code you're running and it ever makes it past the die. Also, my script file was called 'bar' rather than script.ftp in this case.

        Are you sure lftp is in your path when the program is run? You might have to supply the full path.