in reply to vanishing system call

I've tried -w, $!, and all that to try and catch any sort of error, but nothing happens ... The system call is just ignored. It's weird!

Show us how you're checking for errors.

The doc for system (perldoc -f system) suggests checking $? for details of how the child process dies.

Several factors could contribute to this no longer working. Over time, the dataset could have outgrown virtual memory, and over time there could be less virtual memory available for other reasons (e.g., more or bigger processes competing for space, disk space getting used up).

Replies are listed 'Best First'.
Re: Re: vanishing system call
by Anonymous Monk on Sep 20, 2002 at 19:48 UTC
    Hi
    Thanks for the suggestions. There are a lot of helpful people here!
    I tried to catch errors like this:
    system(" cat $file | sort -t\\| +1 -2 > $file.out ") || die "can't sort the file: $!";
    ... and I also tried $?. That's the creepy thing - it never even gets that far. It just skips the whole statement altogether.
    I agree with your thoughts about virtual memory, and in fact this server has had some memory problems in the past. It just seems odd to me that I'm not getting some "out of memory" error (which I've seen before on this server) or even an out-and-out crash of the script. I need something to take to the Unix admins to convince them that there's a problem with the server (there are a number of production databases on there, so they won't reboot or anything like that w/o a good reason).
    Oh, I forgot to mention that if I take the "sort" statement and put it in a separate Perl script, then run that to sort the file, it works fine. Which again leads me down the virtual memory path. In the short term, maybe I'll have to do the data processing and then the sort in two separate scripts, called up by a shell script or something. That's ugly but I'll bet it will work.
    Thanks!
      system(" cat $file | sort -t\\| +1 -2 > $file.out ") || die "can't sort the file: $!";

      Generally, system will return 0 when it succeeds not when it fails. That code would die everytime the system call worked.

      Update: As ChemBoy points out in his reply, $! is not what you want to look at. As I pointed out in a reply to another post of ChemBoy's, it only makes sense to look at $! when system returns -1 meaning that the command was not executed. This doesn't change the advice above.

      -sauoq
      "My two cents aren't worth a dime.";
      

        Nice catch on the return value of system--but in error cases, it doesn't set $!, but rather $?. Unfortunately, $? doesn't stringify nearly as nicely as $!, but you can get reasonable information (as outlined in perlvar) with a little extra work:

        unless (0 == system $cmd) { warn sprintf "External command '%s' failed with exit status %d (sig +nal %d). A core dump %s\n", $cmd, $? >> 8, $? & 127, $? & 128 ? "occurred" : "did not occur"; }



        If God had meant us to fly, he would *never* have given us the railroads.
            --Michael Flanders