system call always returns same non-zero value on Linux

On a Athlon box running RHEL3 Linux, I tried to use pgf90 on code which I’d previously used successfully with the g77 compiler and found that the “system” function returns the same non-zero number whether the call is successful or not. [VS g77 giving respective returns of 0 and 256 for successful and unsuccessful cases I tried). Is this a general result for Linux? [If so, it makes g77 a lot more useful than pgf90 in many cases.]

In fortran, when calling an external dummy procedure the compiler does not have access to this code and thus does not “know” what type the return value is. Instead it uses an implicit type base upon the name of the procedure being called. In this case, ‘system’ has an implicit type of ‘REAL’ and is why you getting wrong answers.

To fix this, explictily declare ‘system’ to be an integer.

      program test_system
      INTEGER IRV
      INTEGER system

      IRV = system('rm somefile')
      WRITE(*,*), "Return value is ", IRV
     
      end program test_system



% pgf90 test_system.f
% a.out
rm: cannot remove `somefile': No such file or directory
 Return value is           256
% echo "" > somefile
% a.out
 Return value is             0

g77 works because it’s simply a fortran front end for gcc and lets gcc do the actual compilation.

Thanks for the explanation - I 'll remember that for other cases. It works and I’m glad I’ll be able use pgf90 for my existing programs with some additional adjustments (having already adjusted them from EPC f90 to g77). I had read the PGF77 Reference Manual writeup on “system” and saw it described an an integer function and didn’t realize I had to do more.