How to Run an Executable Programmatically in LabVIEW

Updated Oct 17, 2019

Reported In

Software

  • LabVIEW

Operating System

  • Windows

Issue Details

I have an application or executable (*.exe file) that I would like to call from within my LabVIEW application. How do I launch this executable from within my LabVIEW program? What do I do if the executable requires or can take input options?

Solution

The usual method for calling a *.exe file in LabVIEW is to use the System Exec VI. The System Exec VI is located in the Communications palette in LabVIEW 7.x or the Connectivity»Libraries & Executables palette in LabVIEW 8.x and higher.

The System Exec VI accepts a string input to be executed in the Windows Command Prompt. 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). Otherwise, you will need to include the full filepath of the executable in the command line input and include the file path to the folder of the executable in the working directory input. See Additional Information for examples on how to implement the System Exec VI.
 
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.

Additional Information

For an example of using the System Exec VI, refer to the Calling System Exec VI in the <LabVIEW>\examples\comm directory in LabVIEW 2012 and lower, or to the Command Line Execution VI in the <LabVIEW>\examples\Connectivity\Libraries and Executables directory in LabVIEW 2013 and higher. Alternatively, refer to the LabVIEW Snippet below for a simple way to run the Windows Notepad program from within LabVIEW (minimum of LabVIEW 8.0 required).



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. Following you find an example 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.

WAS THIS ARTICLE HELPFUL?

Not Helpful