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

why does perl system function returns -1, and $! has 'no child process' even though the command execution goes fine ( redirected result it is properly available - which ensures command executed correctly )

And just before executing $SIG{'CHLD'} is set to DEFAULT. What can be the reason for the -1 returned? Command executed is date command.
  • Comment on system returns -1 even though command executed successfully

Replies are listed 'Best First'.
Re: system returns -1 even though command executed successfully
by Eliya (Vicar) on Jan 10, 2012 at 16:20 UTC

    Here's an arbitrary example that (on my system) behaves as you describe:

    $SIG{CHLD} = sub { wait }; system "date && foo 2>/dev/null"; print "ret: $?\n"; print "err: $!\n"; _END__ Tue Jan 10 17:19:35 CET 2012 ret: -1 err: No child processes

    The -1 is because of the failed foo. and the "no child processes" (ECHILD) is because of the SIGCHLD reaper getting called without there being an unreaped child process (system() itself has already reaped it).

    As you haven't shown what exactly you're doing, I'll leave it up to you to check for possible similarities with your code...

Re: system returns -1 even though command executed successfully
by Anonymous Monk on Jan 10, 2012 at 14:11 UTC

    why does perl ... {{{ no code shown }}

    :) Maybe your copy of perl or date hates you? Mine doesn't return -1 when nothing is wrong

    $ perl -le " print system qw/ date / " Tue Jan 10 06:14:05 PST 2012 0