QuickBasic Cannot RUN or CHAIN to Batch Files; Use SHELL (45908)



The information in this article applies to:

  • Microsoft GW-BASIC 3.2
  • Microsoft GW-BASIC 3.22
  • Microsoft GW-BASIC 3.23
  • Microsoft QuickBASIC 1.0
  • Microsoft QuickBASIC 1.01
  • Microsoft QuickBASIC 1.02
  • Microsoft QuickBASIC 2.0
  • Microsoft QuickBASIC 2.01
  • Microsoft QuickBASIC 3.0
  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0

This article was previously published under Q45908

SUMMARY

Batch (.BAT) files can be executed only from a Basic program SHELL statement. The RUN and CHAIN statement cannot be used to execute a batch file.

This information applies to the following Basic products:

  1. Microsoft GW-Basic Versions 3.20, 3.22, and 3.23
  2. QuickBasic Versions 1.00, 1.01, 1.02, 2.00, 2.01, 3.00, 4.00, 4.00b, and 4.50
  3. Microsoft Basic Compiler Versions 6.00, and 6.00b for MS-DOS and MS OS/2.
  4. Microsoft Basic PDS Version 7.00 for MS-DOS and MS OS/2.

MORE INFORMATION

The SHELL statement can be used to execute a .COM, .EXE, or .BAT file, or almost any MS-DOS command, and then return to the original Basic program. However, the SHELL statement cannot pass any information or variables to the program or statement it is executing.

The statement or program being executed from the SHELL statement is being executed as a "child" process of Basic. The Basic program is exited (but remains in memory), the command string is executed, and then control is returned to the Basic program. Two methods can be used to pass information down to a batch file:

  1. Write the information to a file and have the batch file access the file for the necessary information.
  2. Set a special environment variable with ENVIRON that can be read by the batch file.
The RUN and CHAIN statements expect to RUN or CHAIN to a program that has an extension of .BAS or .EXE, depending on whether the program is being executed within the QB.EXE or QBX.EXE environment or as a compiled application.

For more information, consult the Basic language reference manual included with your Basic package.

Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB45908