system

Run command in Linux shell on Raspberry Pi hardware

Syntax

system(mypi,command)
system(mypi,command,sudo)

Description

example

system(mypi,command) runs a command in the Linux® command shell on Raspberry Pi™ hardware. This function does not allow you to run interactive commands.

example

system(mypi,command,sudo) runs a command with superuser privileges. This syntax is not supported in MATLAB® Online™.

Examples

collapse all

You can run a command that lists the contents of a folder.

system(mypi,'ls -al')
ans =

total 100
drwxr-xr-x 10 pi   pi    4096 Nov 22 14:18 .
drwxr-xr-x  3 root root  4096 Sep 25 16:22 ..
-rw-------  1 pi   pi   21712 Nov 13 17:40 .bash_history
-rw-r--r--  1 pi   pi     220 Sep 25 16:22 .bash_logout
-rw-r--r--  1 pi   pi    3243 Sep 25 16:22 .bashrc
drwxr-xr-x  4 pi   pi    4096 Oct  1 18:17 .cache
drwxr-xr-x  6 pi   pi    4096 Oct  2 12:01 .config
drwx------  3 pi   pi    4096 Oct  1 18:17 .dbus
drwxr-xr-x  2 pi   pi    4096 Nov 13 17:30 Desktop
-rw-r--r--  1 pi   pi      35 Nov 13 17:41 .dmrc
drwx------  2 pi   pi    4096 Oct  1 18:17 .gvfs
drwxr-xr-x  3 pi   pi    4096 Oct  2 14:46 MATLAB 
-rw-r--r--  1 pi   pi    5781 Feb  3  2013 ocr_pi.png
-rw-r--r--  1 pi   pi     675 Sep 25 16:22 .profile
drwxrwxr-x  2 pi   pi    4096 Mar 10  2013 python_games
drwxr-xr-x  8 pi   pi    4096 Oct  2 12:41 wiringPi
-rw-------  1 pi   pi      66 Nov 13 17:41 .Xauthority
-rw-------  1 pi   pi     261 Nov 13 17:41 .xsession-errors
-rw-------  1 pi   pi     449 Nov 13 17:40 .xsession-errors.old

You can run a command with superuser privileges.

system(mypi,'cp /etc/network/interfaces int.copy','sudo')

You can run the ls command on the Raspberry Pi hardware when connected to it from MATLAB Online. Other Linux commands are not supported. To use your hardware from MATLAB Online, follow the instructions in Connect to Raspberry Pi Hardware Board in MATLAB Online.

When connected to your hardware from MATLAB Online, the default working directory is /home/matlabrpi, instead of /home/pi. Use ls to list the contents of this folder. You can append any of the ls command flags to display more information about the files. In this example, the -al option lists the long format and includes hidden files.

system(mypi,'ls -al')
ans =

total 100
drwxr-xr-x 10 pi   pi    4096 Nov 22 14:18 .
drwxr-xr-x  3 root root  4096 Sep 25 16:22 ..
-rw-------  1 pi   pi   21712 Nov 13 17:40 .bash_history
-rw-r--r--  1 pi   pi     220 Sep 25 16:22 .bash_logout
-rw-r--r--  1 pi   pi    3243 Sep 25 16:22 .bashrc
drwxr-xr-x  4 pi   pi    4096 Oct  1 18:17 .cache
drwxr-xr-x  6 pi   pi    4096 Oct  2 12:01 .config
drwx------  3 pi   pi    4096 Oct  1 18:17 .dbus
drwxr-xr-x  2 pi   pi    4096 Nov 13 17:30 Desktop
-rw-r--r--  1 pi   pi      35 Nov 13 17:41 .dmrc
drwx------  2 pi   pi    4096 Oct  1 18:17 .gvfs
drwxr-xr-x  3 pi   pi    4096 Oct  2 14:46 MATLAB 
-rw-r--r--  1 pi   pi    5781 Feb  3  2013 ocr_pi.png
-rw-r--r--  1 pi   pi     675 Sep 25 16:22 .profile
drwxrwxr-x  2 pi   pi    4096 Mar 10  2013 python_games
drwxr-xr-x  8 pi   pi    4096 Oct  2 12:41 wiringPi
-rw-------  1 pi   pi      66 Nov 13 17:41 .Xauthority
-rw-------  1 pi   pi     261 Nov 13 17:41 .xsession-errors
-rw-------  1 pi   pi     449 Nov 13 17:40 .xsession-errors.old

You can also specify any other folder to list its contents.

system(mypi,'ls /home/pi')
ans =

    'cap.jpg
     debug.log
     Desktop
     Documents
     Downloads
     matlab_online_login.expect
     matlab-rpi.deb
     Music
     Pictures
     Public
     python_games
     Templates
     Videos'

Input Arguments

collapse all

Connection to a specific Raspberry Pi hardware board, specified as a raspi object.

Linux command, specified as string.

Example: 'ls -al'

sudo command, specified as string. This syntax is not supported in MATLAB Online.

Example: 'sudo'

Data Types: char

Extended Capabilities