Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29393 토론

Unexplained return from SYSTEM() function

Keith_R_
초보자
614 조회수
I am having a problem with the return code from the SYSTEM intrinsic
function.

The code is question is simply attempting to rename a file:

    status=system("mv -f "//from_file//" "//to_file)
    if (status/=0) call io_abort('Error in renaming '//from_file//' to '//to_file)

On most systems this works perfectly well. But on just 3 systems the
status code returned is non-zero, although the rename apparently
succeeded. A slightly deeper investigation reveals a puzzle -
the code returned by "system" is greater than 256. In fact the least
significant byte is zero and the second-least significant byte is nonzero.

According the the "system" entry in the manual this is just the status
code returned by the shell, which according to the bash manpage must
be < 256. It looked as if the rename actually succeeded but that the
system is returning an unexpected status.

In all of the failing cases the file concerned is on a network file
system; one case is AFS, and the other two are panasus filesystems
mounted using NFS. All of the cases were of x86_64 architecture and
the 64-bit compilers were used (9.1.039).

How is it possible for SYSTEM() to return a 16-bit error code? And
if so how should it be interpreted to determine success or failure
of the called command?

Keith Refson

0 포인트
1 응답
jimdempseyatthecove
명예로운 기여자 III
614 조회수

I think to be safe use IAND to produce a result containing the low 8 bits of the return code from SYSTEM.

result = (IAND(SYSTEM(string), 255)
if(result .NE. 0) then
write(*,*) "System error", IERRNO()
endif

0 포인트
응답