Pass Command Line Arguments to a LabVIEW Executable

Updated Nov 13, 2017

Reported In

Software

  • LabVIEW Full

Issue Details

How can I pass command line arguments to an executable built in LabVIEW?

Solution

It may be desirable to have a LabVIEW executable start up in different states or with different input parameters. When you launch a LabVIEW executable from the command line, you can pass user-defined arguments to the application as long as the machine has the appropriate Run-Time Engine and necessary drivers. The following describes how this is accomplished. Note that the syntax for calling a LabVIEW executable with command line arguments differs between versions of LabVIEW. 
When LabVIEW passes the arguments from the command line to the LabVIEW executable, you can reference the arguments on the block diagram by using the Application:Command Line Arguments selection of a property node, as shown in figure 1.
 

Figure 1. Arguments Property Node
 
The arguments come in as an array of strings. The first element in the array is always the name of the application.
 
  • LabVIEW 8.0 and later
With the introduction of the project in LabVIEW 8.0, you first need to enable the passing of command line arguments in the application's build specification. In order to do this follow these steps:
  1. Right click Build Specifications in the Project Explorer of the completed project
  2. Select new and then Application (EXE)
  3. Navigate to the Advanced category
  4. Check the Pass all command line arguments to application box
 

Figure 2. Advanced Category Check Box
 
To pass the command line arguments to the application and access them in your code, run the executable from the Command Prompt and add input arguments separated by spaces. For example, if test.vi was built into an executable, it could be called by the following, where 1000 and sine are both command line arguments:= 
"<build directory>\test.exe" 1000 sine 
If the option to pass all command line arguments to application is not selected in the build specification, the application can still receive command line arguments by using the syntax for LabVIEW 7.x. 

Additional Information

 
  • LabVIEW 7.x
User-defined arguments start after two hyphens (– –) surrounded by spaces in the command line. For example, using the same LabVIEW exectuable as mentioned above; test.exe, it could be called by the following:

"<build directory>\test.exe" –– 1000 sine
 
  • LabVIEW 6.1 or Earlier
Windows: Use the Windows API GetCommandLine() function to read the command line which launched the current application. Parse through the string returned from the function to obtain the arguments from the command line.

UNIX: LabVIEW cannot directly read command-line arguments on UNIX systems, but it can read environment variables. Run LabVIEW with an environment variable set to the arguments you wish to pass. For example, in bash execute the following line: LVARGS="arg1 arg2 arg3" labview &. Now in System Exec VI, use echo $LVARGS as the command line string and use the returned string in your application. The same line in bash also works for a LabVIEW executable by changing Labview in the line above to the name of the executable. 

For more information about using command line arguments in LabVIEW, refer to the related links below or search for "command line" in the LabVIEW Help.

WAS THIS ARTICLE HELPFUL?

Not Helpful