Documentation Center

  • Trial Software
  • Product Updates

system

Run command in Linux shell on Raspberry Pi hardware

Syntax

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

Description

system(mypi,command) runs the command in the Linux® command shell on Raspberry Pi™ hardware.

system(mypi,command,sudo) runs the command with superuser privileges.

Examples

expand all

Run a Linux Command on the 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');

Input Arguments

expand all

mypi — Connection to specific boardhandle

Connection to a specific board, specified as a handle.

Use raspi to create this connection.

Example: mypi

command — Linux commandcommand

Linux command, specified as string.

Example: 'ls -al'

sudo — sudo commandsudo

sudo command, specified as string.

Example: 'sudo'

Data Types: char

See Also

Was this topic helpful?