This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Running Shell Commands and Custom Applications in Linux Real-Time OS from LabVIEW

Updated Mar 11, 2019

Reported In


  • myRIO-1950
  • myRIO-1900
  • cRIO-9067
  • cRIO-9066
  • cRIO-9038
  • cRIO-9065

Operating System

  • NI Linux Real-Time
  • Linux

Programming Language

  • C
  • C++

Issue Details

I have an NI device that runs Linux Real-Time and I would like to send it Shell commands from LabVIEW or custom compiled C or C++, how can I do this?


This article will discuss how to do this with the System Exec VI in a Shell-like interface. If you are interested in an alternative method please see Using WebDAV to Transfer Files to Your Real-Time Target.

1. Install the appropriate GNU C compiler

The suggested compiler is gcc 4.4.1 with soft fp. Mentor Graphics provides a free (Lite) version of this compiler called Mentor Graphics Sourcery G++ Lite 2010.09-50 for ARM GNU/Linux. Please note that, since this is a third party product with its own limitations, no direct support can be provided from National Instruments.
2. Write your C or C++ program to be launched from Shell
The following code block is an example written in C, which will be used as a reference:
#include <stdio.h>
int main(int argc, char *argv[])
                int sum, num1, num2 = 0;
                if(argc == 1)
printf("no arguments specified");
                else if(argc == 3){
                sscanf(argv[1], "%d", &num1);
                sscanf(argv[2], "%d", &num2);
                sum = num1+num2;
                printf("%d", sum);          
printf("incorrect number of  arguments specified");
                return 0;

3. Compile it on the Windows command line 
For example:  
cd "path to the C file"\  
arm-none-linux-gnueabi-gcc -o test main.c

In this case, the C code file is called main.c and the compiled file will be called test.

4. Copy the file over to the target
The easiest way to do this is to use a mapped-drive with WebDAV protocol on Windows 7 to home/lvuser directory on the LinuxRT target. For more information, see the KnowledgeBase article in 'Related Links' below, on using WebDAV to transfer files to your real-time target.

5. Set the file permission for read and execution 
SSH into the target and set the appropriate permission to the test file by typing in chmod 777 (777 argument changes the permission of the file to read, write, and execute for all). 
chmod 777 /home/lvuser/test

To SSH into the target, any terminal program (e.g. PuTTY) can be used. Use the regular target IP address and port number 22.

6. Access and run the file from LabVIEW 
Write a simple LabVIEW application that concatenates the test file called and arguments into a Shell call string, and use the System to call the compiled C code. See below for an example.

    Additional Information

    There are two general ways to run custom C or C++ code on a LinuxRT device in a LabVIEW VI. The user can either compile the code into an executable and run it using the System Exec VI, or a shared library can be compiled and functions can be accessed with the Call Library Function Node.


    Not Helpful