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

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.

Replies are listed 'Best First'.
Re^6: Perl die after executing external program
by aullah (Initiate) on Apr 29, 2011 at 13:46 UTC
    Yes, I'm sure because I can see the output on terminal while executing the code with debugging ON. But problem is STDOUT/STDERR is not returning any value except 0.

      STDOUT or STDERR should neither one return a numeric 0. They should only return a string (although the string could be '0' if that's what the program you executed wrote to one of those handles).

      If you're getting a numeric 0, you're getting it from a system call or a pipe. In scalar context the backticks will return either a string or undef. perlop says so. In a list context, it will be a list of lines or an empty list. Again, perlop says so.