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

this is quite possibly a unix problem, not a perl one, but i am getting it via perl, so i have to start here...

in short, everything system call i'm making from a particular perl program returns 16777215 instead of zero. when i paste the relevent code into a new script to quickly test it alone, it returns 0. both do the same thing, with no errors.

the manner of calling can be system() or backticks, no difference. i am using root to run both the real program (a daemon...) and any test variants. any program i call on a shell returns 16777215, whether it is mv, rm, tar, etc... the program and any testing snippets are run from the same directory, with the same permissions, on the same files. the only difference in testing is that i'm not bothering to listen to a socket, i don't have a user connected to that socket, and i'm not fork()ing or eval()ing before i get to making the shell call...

the best solution i have is to find perl modules to do everything i already have perfectly good system calls to for... and i don't want to install new perl modules where i can possibly avoid it. it's worth avoiding having to update multiple servers to add a perl module for tar when they all have /usr/bin/tar already...

but a solution is not entirely what i need. i still don't know what the problem is... best guess there is a something like taint but with no complaints from perl as i'm not using taint... wouldn't know if the system can do that, but if anyone else would, it's a BSD (darwin) with perl 5.8.0
... my @output = `@command`; print $? >> 8, "\n";

this snippet is, verbatim, with anything i want in @command -- system() does the same, as i mentioned. contents of @output are exactly what they should be, files are manipulated as they should be, nothing ever on STDERR unless the command is wrong. (in which case i do get other error codes)

Replies are listed 'Best First'.
Re: bizzare exit code
by jmcnamara (Monsignor) on Aug 20, 2002 at 12:22 UTC

    It looks like the command is returning -1:
    perl -le 'print -1 >> 8' 16777215

    Which may indicate that the command isn't valid:

    perl -le '`foobar`' -1

    Or if the command is valid, then perhaps the return value of -1 indicates that your program doesn't have permission or resources to run it.

    --
    John.

Re: bizzare exit code
by waswas-fng (Curate) on Aug 20, 2002 at 15:21 UTC
    How are you running the perl script that execs the commands? from cgi? cron? command line? Is it possible that the PATH is messed up and you are trying to exec `tar` for instance where tar is not in the path when the script runs? I dont have any BSD boxes here to test on but I think that -1 is returned where the command is not found.

    -Wade Stuart
Re: bizzare exit code
by Xanatax (Scribe) on Aug 21, 2002 at 10:00 UTC
    hrm, yes... 16777215 is in fact -1, but i've seen in a number of places that the error code is $? >> 8, so i report unsigned i guess...

    the reason this is most boggling for me is that everything works fine but i get an error code. and the same bloody error code for any and all programs i call.

    anything that would result in real errors, like $PATH being wrong, should also preclude correct running of the programs in question... and it isn't particularly replicatible, when i copy sections of code and run them, they do all the same things but with correct error codes...