Microsoft KB Archive/50637

= PRINT # to &quot;CONS: &quot; and PRINT Can Use > for DOS Redirection =

Article ID: 50637

Article Last Modified on 8/16/2005

-

APPLIES TO


 * 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



SUMMARY
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 &quot;>&quot; 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.



MORE INFORMATION
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 &quot;CONS:&quot; device OPENed for output (OPEN &quot;CONS:&quot; 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

or

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

or

QBI > myfile.dat The screen output obtained by opening the &quot;SCRN:&quot; 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
OPEN &quot;CONS:&quot; FOR OUTPUT AS #1 OPEN &quot;SCRN:&quot; FOR OUTPUT AS #2

PRINT &quot;This is a regular print&quot; PRINT #2, &quot;This is a print to scrn:&quot; PRINT &quot;This is a regular print&quot; PRINT #1, &quot;This is a print to cons:&quot;

CLOSE #1 CLOSE #2 END 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

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.