How Do I Execute a Windows Command in LabVIEW?

Updated Jan 2, 2018

Reported In

Software

  • LabVIEW Base
  • LabVIEW Full
  • LabVIEW Professional

Operating System

  • Windows

Issue Details

I want to execute a Windows command line command in LabVIEW.  How can I accomplish this?

Solution

There are two ways to accomplish this functionality. Both methods use the System Exec VI which can be found in the Connectivity » Libraries & Executables palette.
 
  • The following code executes the dir command on the C:\ directory and outputs the result to a String Indicator. If you use this method, you won't see a command prompt window. LabVIEW will open it, run the command and return the string result. LabVIEW will wait until the result is returned before continuing with the program. In certain circumstances, it is necessary to include the new line character (\r\n) after the dir command.  Put this character in the String Constant by pressing Enter after the command.
 

 
  • Alternatively, the implementation shown below will open a command prompt window and execute the dir command on the C:\ within the command prompt. The /k argument forces the command prompt window to stay open so that you can see the results of the dir command. Using this method, LabVIEW and the command prompt window will run asynchronously. In other words, after starting the command window and passing the command to it, LabVIEW will continue executing the next VI in your code while the command prompt window responds to the dir command.
 

Additional Information

You can also use the System Exec.vi to call VBscript files if you need to automate a bigger set of commands,

WAS THIS ARTICLE HELPFUL?

Not Helpful