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

I am using the Net::SCP::Expect pm in a script and it is causing a system command to give a return value of -1 instead of 0. I know it is the problem as I wrote a test script and as you can see adding and removing the “use Net::SCP::Expect” line will change the return value.
#!/bin/env perl use strict; use warnings; use Net::SCP::Expect; my $cmd = qq{rpm -qa | grep cluster}; print (" - Running ($cmd) \n"); my @out = `$cmd`; my $err = $?; if ($err) { print "Could not find cluster rpm's, err: $err +\n"; exit 1; } exit 0;
Does anybody know how to fix/get around this?

Replies are listed 'Best First'.
Re: Net::SCP::Expect causes error in return code
by Illuminatus (Curate) on Dec 06, 2010 at 16:22 UTC
    Given the indentation, I am guessing you removed code you deemed unnecessary. When you say 'removing the "use Net::SCP::Expect" line...', is it really the case that you are not actually creating any objects using the module? Or have you commented out these too? They may be important.

    Another thing you could do is try to see what the command is saying when it fails. You could replace

    my $cmd = qq{rpm -qa | grep cluster};
    with
    my $cmd = qq{rpm -qa &> /tmp/bad_call };
    (replace &> with something else if bash is not your default shell) Then look at /tmp/bad_call to see what it reported.

    fnord

Re: Net::SCP::Expect causes error in return code
by sierpinski (Chaplain) on Dec 06, 2010 at 14:23 UTC
    What is the actual result? I get an error in trying to use /bin/env (bad interpreter)...

    Honestly I've never seen that used, but it might be chalked up to ignorance. What result do you get with #!/usr/bin/perl?

    Another thing, how are you calling this? I know exec and system have different return values. System returns the return code, and exec doesn't return anything useful (since it either fails (command not found) or never returns (forks to new process)

    Edit: typo
      #!/bin/env perl is a common device for using the PATH environment variable to find perl rather than hard-coding the absolute name. I doubt it is relevant.
        Thanks for the info. Learn something new every day!