Microsoft KB Archive/50637

From BetaArchive Wiki
Knowledge Base

PRINT # to "CONS: " and PRINT Can Use > for DOS Redirection

Article ID: 50637

Article Last Modified on 8/16/2005


  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS
  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 6.0b
  • Microsoft BASIC Professional Development System 7.0

This article was previously published under Q50637


In a Microsoft QuickBasic program, the output from either a compiled or interpreted program can be redirected from the SCREEN to a file by using the redirection ">" operator in MS-DOS. This will also redirect stream devices, such as the LPT1 printer, to MS-DOS.

This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50 for MS-DOS, to Microsoft QuickBasic Interpreter (Academic Edition) Version 1.00, and to Microsoft Basic Compiler Versions 6.00, and 6.00b for MS-DOS and MS OS/2, and to Microsoft Basic PDS Version 7.00 for MS-DOS and MS OS/2.


The following are the only two forms of output from Basic that can be redirected to a file:

  1. Output from the standard PRINT statement
  2. Output from the PRINT #Num, statement, where #Num is the "CONS:" device OPENed for output (OPEN "CONS:" FOR OUTPUT AS #Num)

Also, if you are testing a program inside the editor environment in QB.EXE from QuickBasic Version 4.00, 4.00b, or 4.50, QBX.EXE from Basic PDS 7.00, or in QBI.EXE from QuickBasic Interpreter (Academic Edition) Version 1.00, you can redirect the output of all programs run in the environment, as follows:

   QB  > LPT1
   QBX > LPT1


   QBI > LPT1

The QB, QBX, or QBI editor environment will behave normally, but output from the Basic program running in the environment will be redirected to the printer. You can also redirect to a file on disk as follows:

   QB  > myfile.dat
   QBX > myfile.dat


   QBI > myfile.dat

The screen output obtained by opening the "SCRN:" FOR OUTPUT AS #Num2, and executing the statement PRINT #Num2 can't be redirected to a file.

The following is an example of redirecting the output of a QuickBasic program to a file:

Code Example


PRINT "This is a regular print"
PRINT #2, "This is a print to scrn:"
PRINT "This is a regular print"
PRINT #1, "This is a print to cons:"


Once the program is compiled, you can redirect the output to a file by executing the following line at the DOS prompt:

   EXEName > OutputFileName

When this is executed, the OutputFileName will contain the following:

This is a regular print
This is a regular print
This is a print to cons:

And the screen will contain the following:

This is a print to scrn:

Additional query words: QuickBas BasicCom

Keywords: KB50637