Overview
This function reads terminal commands from a text file, executes the commands in the terminal, and reads the output of the command from the terminal from LabVIEW. The program was tested on OpenSUSE 13.1 using standard terminal commands. The commands text file can be modified to run any terminal commands supported by your flavor of Linux from LabVIEW.
Description
The program opens a text file given by the file path location set by the file path constant on the block diagram. The program then parses the text file to a string array. For each command in the string array, the command is checked to see if it is empty and executed otherwise. The program uses the System Exec VI to send commands to the terminal, waits 1 second, and then reads the terminal output using the Read Pipe VI.
Steps to Implement or Execute Code
Requirements
Software
LabVIEW 2011 for Linux or Later
Linux OS
Hardware
None
Additional Images or Video


Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Thank you for the block diagram. I have LabVIEW 2010 and LabVIEW 2013. Unable to open RunTerminalCommandsFromFile.vi Would it be possible for you to upload a VI for either version (File--> Save for Previous Version)?
Hi Kapur,
Sorry about that. I have attached the LabVIEW 2010 version. You will able to open it in 2010 or 2013. Thanks for the comment!
Thanks,
Frank
Hi fblerg,
Any chance you can upload a version for Labview for Mac ?
-Ed-
Hi Ed,
Unfortunately, the Mac version is only available on physical media. You might want to contact sales for a copy if you already have a license.
Thanks,
Frank
Hi fblerg,
Can you upload the sub vi code, because I can't get this code to run without it?
Thank,
Kaitlyn
Hi Kaitlyn,
There should not be any subVIs in this example. Are you missing the Read Pipes VI? These VIs are only available on the Linux version of LabVIEW. So if you are opening this example on Windows, those VIs are not include in the Windows LabVIEW environment and you won't be able to run the example.
If you are using Windows, you can use the Sys Exec VI to execute commands in the cmd prompt. Please see the below KnowledgeBase articles for more info.
https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/menus/default/plat/pipes-mnu.html
https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000YGivCAG&l=en-US
Thanks,
Frank
I have Labview on Windows and I need to execute Linux Shell commands on CRIO.
My Labview Distribution (2014) can't find the attached libraries in your file.
How schould I proceed?
There is no simpler way to send a list of command in Linux?
Thank you in advance.
Carmine
Hi Carmine,
This is example is for executing shell commands on a Linux desktop. The Pipe VIs are not available on Windows. To shell commands on a cRIO, you will have to deploy code and call the System Exec VI on the cRIO. Please see the below KB article for an example of how use the System Exec VI on a cRIO.
https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P9usSAC&l=en-US
Thanks,
Frank