Example Code

Run Terminal Commands from Text File in Linux

Code and Documents

Attachment

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

  1. Download VI and commands text file.
  2. Modify the file path location to the commands text file on the block diagram.
  3. Run the VI to confirm the commands are executed.
  4. Modify VI and commands text file as needed.

Requirements

Software

LabVIEW 2011 for Linux or Later

Linux OS

Hardware

None

Additional Images or Video

RunTerminalFP.png

RunTerminalSnippet.png


Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Kapur
Member
Member
on

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)?

fblerg
NI Employee (retired)
on

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

egoh1026
Member
Member
on

Hi fblerg,

Any chance you can upload a version for Labview for Mac ?

-Ed-

fblerg
NI Employee (retired)
on

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

kearche2
Member
Member
on

Hi fblerg,

Can you upload the sub vi code, because I can't get this code to run without it?

Thank,

Kaitlyn

fblerg
NI Employee (retired)
on

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.

Pipes VIs

https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/menus/default/plat/pipes-mnu.html

How Do I Execute a Windows Command in LabVIEW?

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000YGivCAG&l=en-US

 

Thanks,

Frank

cderrico
Member
Member
on

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

fblerg
NI Employee (retired)
on

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.

 

Memory Reporting Issue with NI Linux Real-Time OS Targets

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P9usSAC&l=en-US

 

Thanks,

Frank

Contributors