FIX: PAUSE Command with Input Redirection in FORTRANLast reviewed: September 11, 1997Article ID: Q67098 |
4.00 4.01 4.10 5.00 | 4.10 5.00
MS-DOS | OS/2kbprg kbfixlist kbbuglist The information in this article applies to:
SYMPTOMSBeginning 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.
STATUSMicrosoft 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 INFORMATIONWhen 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' endData file, TEST.DAT:
VerCommand line:
C:\> TEST < TEST.DATOutput:
Before PAUSE Pause - Please enter a blank line (to continue) or a DOS command. MS-DOS Version x.xx After PAUSEIf 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 endData:
Ver 1Output:
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 encounteredWhen 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' endData:
1 VerOutput:
1 Before PAUSE Pause - Please enter a blank line (to continue) or a DOS command. After PAUSEThese problems are caused by the PAUSE command not reading data from the redirection file in the same way a READ statement would.
WorkaroundsDo 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.
|
Additional reference words: 5.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |