Run an Executable Programmatically in LabVIEW

Updated Dec 15, 2020

Environment

Software

  • LabVIEW

In LabVIEW, you can programmatically call executable (*.exe) files or applications using the System Exec VI. The System Exec VI accepts a string input to be executed in the Windows Command Prompt; to launch an executable, you can use the directory and filename as a string input into the VI.

This tutorial shows you how to use launch an application from LabVIEW using the System Exec VI.
 

  1. Follow steps in Execute Command Line Arguments from LabVIEW to set up and configure your System Exec VI.
  2. Input the full filepath of the executable in the command line
    • If the executable directory is present in the Windows PATH environment variable, you can run the executable by using its filename as this string input (e.g., application_name.exe) and c
  3. Input the file path to the folder of the executable into the working directory 
 

Considerations

  • The System Exec VI does not support calling options following the file name. If your application requires you to call the executable with options, here is what you can do instead:
  1. Create a filename.bat file which calls the executable file followed by the desired options (e.g. filename.exe -option1 -option2).
  2. Then, use the LabVIEW System Exec VI to call the filename.bat file.
  • If you are using LabVIEW 32-bit and trying to call an executable that is located in the C:\Windows\System32 folder, you might see, that the .exe cannot be opened. The reason here is, that you cannot access 64-bit executables via the 32-bit LabVIEW environment.
    • To run those .exe-files, create a batch file, specify the whole path of the .exe and replace System32 with sysnative. This is a special folder that is invisible in the Windows Explorer, but it is used as a File System Redirector to access the 64-bit System32-folder from 64-bit applications or scripts.
      • Here is an example of what a batch file includes that calls, for example, the ie4uinit.exe and hands over the parameter -show
        • C:\Windows\sysnative\ie4uinit.exe -show
  • If you are using LabVIEW 64-bit, then you do not have to change the path from C:\Windows\System32 to C:\Windows\sysnative.
  • Refer to the Command Line Execution VI in the labview\examples\Connectivity\Libraries and Executables directory for an example of using the System Exec VI.

In the snippet below, the System Exec VI is used to run the Windows Notepad program from within LabVIEW.


 Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.