system
Run command in Linux shell on Raspberry Pi hardware
Add-On Required: This feature requires the MATLAB Support Package for Raspberry Pi Hardware add-on.
Description
Examples
Run Linux Commands on Raspberry Pi Hardware
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
Run a Command with Superuser Privileges
You can run a command with superuser privileges.
system(mypi,'cp /etc/network/interfaces int.copy','sudo')
Run Linux Commands on Raspberry Pi Hardware in MATLAB Online
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
mypi
— Connection to Raspberry Pi hardware board
raspi
object
Connection to the Raspberry Pi hardware board, specified as a raspi
object.
command
— Linux command
command
Linux command, specified as string.
Example: 'ls -al'
sudo
— sudo command
'sudo'
sudo command, specified as string. This syntax is not supported in MATLAB Online.
Example: 'sudo'
Data Types: char
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The output of the
system
command is truncated if the length of the output exceeds 16,384 characters.You can deploy
system
on the Raspberry Pi hardware in MATLAB Online.
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)