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

Hi all,

My first post here - hope somebody can help. I'm on Linux - Slackware 12.2 32 bit and Slackware 13.0 64 bit. Both using Perl 5.10.0 as distributed by Slackware. I have 4Gb RAM.

My actual script creates two large arrays, writes some files and then runs a system command to execute PovRay raytracer. It works fine on Slackware 12.2 32 bit but fails on Slackware 13.0 64 bit. The problem is that on Slackware 13.0 64 bit the system command fails to execute. It fails silently and the return code is 0.

I have created a small demo script, see below, which shows the fault using system("date"); It is 100% repeatable on my system. You can see that the second system("date"); command fails to execute on 64 bit.

Anybody able to duplicate this problem? And more important - any solution?

Cheers, Peter

#!/usr/bin/perl system("date"); if ( $? == -1 ) { print "Level 0 command failed: $!\n"; } else { print "Level 0 command exited with value ",($? >> 8),"\n"; } for ($i = 1; $i <= 5760; $i++) { for ($j = 1; $j <= 2880; $j++) { $array1[$i][$j] = "<1234567890,1234567890,1234567890>"; $array2[$i][$j] = "<1234567890,1234567890,1234567890>"; } } system("date"); if ( $? == -1 ) { print "Level 0 command failed: $!\n"; } else { print "Level 0 command exited with value ",($? >> 8),"\n"; } print "End\n"; exit;

Bad output from Slackware 13.0 64 bit:

Tue Feb 16 23:09:22 GMT 2010 Level 0 command exited with value 0 Level 0 command exited with value 0 End

Good output from Slackware 12.2 32 bit:

Tue Feb 16 23:13:52 GMT 2010 Level 0 command exited with value 0 Tue Feb 16 23:14:13 GMT 2010 Level 0 command exited with value 0 End

Replies are listed 'Best First'.
Re: system command - OK on 32 bit, fails on 64 bit Linux - why?
by cdarke (Prior) on Feb 17, 2010 at 09:42 UTC
    I suggest that you print the rest of $?:
    $? & 127 # signal number $? & 128 # dumped core
    See system.
Re: system command - OK on 32 bit, fails on 64 bit Linux - why?
by aquarium (Curate) on Feb 17, 2010 at 01:46 UTC
    What happens if you remove the array code, does then the 64 bit run fine?
    you could do a bit of testing using backticks or open etc equivalents to run the system command, and you'd get to read the stdout and stderr.
    the hardest line to type correctly is: stty erase ^H
Re: system command - OK on 32 bit, fails on 64 bit Linux - why?
by rovf (Priest) on Feb 17, 2010 at 12:03 UTC
    In addition, when doing this type of tests, please always set in the beginning of your program

    $|=1;
    and of course use strict; use warnings;.

    (Note: Typo in Perl code corrected)
    -- 
    Ronald Fischer <ynnor@mm.st>

      I don't see the point of initialising $!.

      • Functions are free to change $! even if no error occurred, and do so. Whatever value you set won't stay there.

        $ echo foo | perl -le'$!=1; print 0+$!; <>; print 0+$!' 1 9
      • $! is meaningless unless a function notified you that it set $!. You can't read $! and compare it against the value you previously gave it. You would think the readline in the above example had failed.

      • die will use $! if it's non-zero, but it will fall back to $?>>8 then to 255. If anything, that means $!=0; would be the best value with which to initialise $!.

      [...] please always set in the beginning of your program $!=1;

      Why? $|=1 would make sense, but $! is just the last error.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Hi guys and thanks,

        I've tried your suggestions and still have the problem. Am now using use strict; use warnings; $!=1;

        The return codes with $? >> 8, $? & 127 and $? & 128 are always 0.
        I get error messages running date via backticks and open(), which seems to indicate that there is no result from the command. (See below).

        BUT - if I reduce the array size then all runs OK!
        Reducing the array to about 5881 x 2562 then my demo script runs OK.
        2562 is not 100% repeatable - seems to depend on what other programs are running.
        Also - it isn't symmetrical. This means that 5881 x 2562 may work, but then 2562 x 5881 doesn't.

        Further suggestions welcomed.

        Cheers, Peter

        Bad results snippet:

        #Finished setup of two arrays 5761 x 2801 #After - using system("date");: #exited with value ($? >> 8) = 0 # #signal number ($? & 127) = 0 # #dumped core ($? & 128) = 0 Use of uninitialized value $cmd in print at ./xpt3.pl line 67. #After - using backticks: readline() on closed filehandle CMD at ./xpt +3.pl line 71. Use of uninitialized value $result in concatenation (.) or string at . +/xpt3.pl line 72. #After - using open: #End
        Good results snippet:
        #Finished setup of two arrays 5761 x 2001 #After - using system("date");: Wed Feb 17 13:13:24 GMT 2010 #exited with value ($? >> 8) = 0 # Wed Feb 17 13:13:24 GMT 2010 #signal number ($? & 127) = 0 # Wed Feb 17 13:13:24 GMT 2010 #dumped core ($? & 128) = 0 #After - using backticks: Wed Feb 17 13:13:24 GMT 2010 #After - using open: Wed Feb 17 13:13:24 GMT 2010 #End

        Code snippet:

        print "#Finished setup of two arrays $i x $j\n"; #Using system() print '#After - using system("date");: '; system("date"); if ( $? == -1 ) { print " #command failed: $!\n"; } else { print " #exited with value (\$? >> 8) = ",($? >> 8),"\n"; } print "# "; system("date"); if ( $? == -1 ) { print " #command failed: $!\n"; } else { print " #signal number (\$? & 127) = ",($? & 127),"\n"; } print "# "; system("date"); if ( $? == -1 ) { print " #command failed: $!\n"; } else { print " #dumped core (\$? & 128) = ",($? & 128),"\n"; } #Using backticks $cmd = `date 2>&1`; print "#After - using backticks: ",$cmd; #Using open() open(CMD, "date 2>&1 |"); $result = <CMD>; print "#After - using open: $result\n"; close(CMD); print "\n#End\n"; exit;

        Sorry, a typo. I meant $|.

        -- 
        Ronald Fischer <ynnor@mm.st>