Microsoft KB Archive/106660

= RUN /N Not Working Correctly with MS-DOS Batch File =

Article ID: 106660

Article Last Modified on 12/3/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft FoxPro 2.5b
 * Microsoft FoxPro 2.5a
 * Microsoft FoxPro 2.5b

-



This article was previously published under Q106660



SUMMARY
In FoxPro for Windows versions 2.5, 2.5a, and 2.5b, the order in which lines of code are executed within a program file may seem to be altered when you are using the RUN command with a /N parameter to execute an MS-DOS executable or batch file. The /N parameter stands for NOWAIT and allows program execution to continue before the command is completed. This makes it seem as if the MS-DOS batch file is not being executed until after the other commands.



MORE INFORMATION
In FoxPro for Windows, the /N parameter is used for calling Windows-based applications with the RUN command. The /N parameter of the RUN command has an optional numeric value that can be included immediately after it to specify how the Windows-based application is opened. The possible settings include /N1, /N2, /N3, /N4, and /N7.

These parameters are not intended for use with MS-DOS executables or batch files. If any of these parameters are used to call an MS-DOS executable or batch file, Windows will execute the file in the background and FoxPro will remain the active application.

Steps to Reproduce the Behavior
 In FoxPro for Windows, from the File menu, choose New. Select File, and then choose the New button. In the text editing window, type "DIR" (without the quotation marks). From the File menu, choose Save, and use RUNTEST.BAT as the filename. Choose the Save button. From the File menu, choose New. Select Program, and then choose the New button.  Enter the following two lines of code in the program window: RUN /N4 runtest.bat WAIT WINDOW "This is a test" </li> From the File menu, choose Save, and use ATEST.PRG as the program name. Choose the Save button.</li>  Run the program you just created, by issuing the following command in the Command window: DO atest </li></ol>

The WAIT WINDOW message will appear on the screen before FoxPro shells to MS-DOS to execute the RUN command. This is because the batch file is running in the background, while FoxPro continues to execute the program code. This makes it seem like the WAIT WINDOW command is executed before the batch file, when actually both commands are being executed simultaneously under the multitasking environment.

To correct this situation, remove the /N parameter from the RUN command. For example: RUN runtest.bat This allows FoxPro to execute the RUN command first and then execute the following code after returning from the RUN command.

<div class="references_section">