FIX: PAUSE Command with Input Redirection in FORTRAN

Last reviewed: September 11, 1997
Article ID: Q67098
4.00 4.01 4.10 5.00 | 4.10 5.00
MS-DOS              | OS/2
kbprg kbfixlist kbbuglist

The information in this article applies to:

  • Microsoft FORTRAN for MS-DOS, versions 4.0, 4.01, 4.1, and 5.0
  • Microsoft FORTRAN for OS/2, versions 4.1 and 5.0

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:

   Ver
   1

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:

   1
   Ver

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.


Additional reference words: 5.00
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: FORTLngIss
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 11, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.