FIX: PAUSE Command with Input Redirection in FORTRAN (67098)
The information in this article applies to:
- Microsoft FORTRAN Compiler for MS-DOS 4.0
- Microsoft FORTRAN Compiler for MS-DOS 4.01
- Microsoft FORTRAN Compiler for MS-DOS 4.1
- Microsoft FORTRAN Compiler for MS-DOS 5.0
- Microsoft FORTRAN compiler for OS/2 4.1
- Microsoft FORTRAN compiler for OS/2 5.0
This article was previously published under Q67098 SYMPTOMS
Beginning with Microsoft FORTRAN version 4.0, the PAUSE command allows you
to execute operating system commands while program execution is suspended.
When program input is redirected from the keyboard to a file, the PAUSE
statement does not work correctly if the program READs from the redirection
file or if the program contains multiple PAUSE statements.
STATUS
Microsoft has confirmed this to be a problem in FORTRAN versions 4.x
and 5.0. This problem was corrected in FORTRAN version 5.1.
MORE INFORMATION
When input is redirected from a file and the only data read from the
file is one MS-DOS command for a PAUSE statement, the program works
correctly. The following short program gives an example:
Sample Code
write(*,*) 'Before PAUSE'
pause
write (*,*) 'After PAUSE'
end
Data file, TEST.DAT:
Ver
Command line:
C:\> TEST < TEST.DAT
Output:
Before PAUSE
Pause - Please enter a blank line (to continue) or a
DOS command.
MS-DOS Version x.xx
After PAUSE
If another PAUSE statement is added to the program, only the command
for the first PAUSE is executed. The program appears to read to the
end of the redirection file when it encounters the first PAUSE. If a
READ statement is added to the program after the PAUSE statement, as
in the next example, the program again reads to the end of the file.
In this case, ERROR 6501 is generated.
Code:
integer i
write(*,*) 'Before PAUSE'
pause
write (*,*) 'After PAUSE'
read(*,*) i
write (*,*) i
end
Data:
Output:
Before PAUSE
Pause - Please enter a blank line (to continue) or a DOS command.
MS-DOS Version x.xx
After PAUSE
run-time error F6501: READ(CON)
- end of file encountered
When the READ statement is before the PAUSE statement, the DOS command
is not executed:
Code:
integer i
read(*,*) i
write (*,*) i
write(*,*) 'Before PAUSE'
pause
write (*,*) 'After PAUSE'
end
Data:
Output:
1
Before PAUSE
Pause - Please enter a blank line (to continue) or a
DOS command.
After PAUSE
These problems are caused by the PAUSE command not reading data from
the redirection file in the same way a READ statement would.
Workarounds
Do not use redirection on a program with more than one PAUSE
statement or a combination of PAUSE and READ statements.
Use the OPEN command to open a file to be used for input
for READ statements.
Use calls to the C functions SYSTEM or SPAWNLP instead of PAUSE
statements to execute DOS commands. For more information on these
functions, see page 86 of the "FORTRAN Advanced Topics" manual for
version 5.00 or the DEMOEXEC.FOR program included with versions 4.x
and 5.00 of FORTRAN.
This problem does not occur in earlier versions of FORTRAN because the
functionality of the PAUSE statement is different. In earlier
versions, you are not allowed to execute DOS commands after a PAUSE.
Modification Type: | Major | Last Reviewed: | 12/1/2003 |
---|
Keywords: | kbbug kbfix KB67098 |
---|
|