Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
91 ratings:
 3.82 out of 5   

How Do I Run an Executable or External File from within LabVIEW?



Primary Software: LabVIEW Development Systems>>LabVIEW Base Development System
Primary Software Version: 1.0
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
I have an executable (*.exe file) that was created in a different programming environment. This executable runs an application 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.

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. Or, refer to the LabVIEW Snippet below for a simple way to run the Windows Calculator program from within LabVIEW (minimum of LabVIEW 8.0 required).

Unfortunately, the System Exec VI does not support calling options following the file name.  In order 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 and those options will be ported over.
Furthermore, you can also directly call an external file that is not an executable. For example, we will use a file named My Document.txt. You cannot type My Document.txt into the command line input of the System Exec VI. You can, however, type Notepad My Document, and the System Exec VI will open the text file in Notepad.


Figure 1: Windows Calculator Example



Related Links:
NI Community: Launch a File Programmatically in its Default Application
KnowledgeBase 2MPCL53N: How Do I Execute a Windows Command in LabVIEW?
LabVIEW Help: System Exec VI

Attachments:
Open Calculator.vi




Report Date: 06/28/1997
Last Updated: 06/30/2015
Document ID: 0YR9TGW1

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit