Programmatically Force the Command Prompt Window to Close after Using the System Exec VI?

Updated Jan 10, 2023

Reported In

Software

  • LabVIEW Full
  • LabVIEW Base

Issue Details

When I run a batch file (*.bat) from LabVIEW using the System Exec VI, the resulting DOS window (or taskbar item, if the run minimized) remains open after the batch file completes. How can I make it close?

Solution

There are three ways to force the Command Prompt to close after being called in LabVIEW:
  1. The simplest method is to wire a True Constant to the wait until completion? input to the System Exec VI.
  2. A more general solution is to use the command .com program with the /C flag and your batch file as the argument. For example, use the following argument for the System Exec VI. This method does not require any edit of the batch file.
  3. If editing the batch file is not a concern, you may add the line exit at the end of the file to get the window to close.
  4. For operating systems previous to Windows 7:  Edit the properties of the batch file to force it to close on exit (right-click on the batch file and select Properties » Program). This creates a *.pif file in the same directory that Windows uses to control the window behavior when the batch file is run.