Execute UNIX command and return output
status = unix(command)
[status,cmdout] = unix(command)
[status,cmdout] = unix(command,'-echo')
List all users who are currently logged in, and save the command exit status and output. Then, view the status.
command = 'who'; [status,cmdout] = unix(command); status
status = 0
status of zero indicates that the command
completed successfully. MATLAB returns a string containing the
list of users in
status— Command exit status0 | nonzero integer
Command exit status, returned as either
a nonzero integer. When the command is successful,
status is a nonzero integer.
command includes the ampersand
the exit status when
command does not include the
ampersand character (
the exit status upon
Output of the operating system command, returned as a string. The system shell might not properly represent non-Unicode® characters.
MATLAB converts characters to the encoding that your operating
system shell accepts. Output from the
converted to the MATLAB encoding to be displayed in the command
window. If you get unexpected results from the command, enter the
directly at the operating system prompt to see how the operating system
treats your input.
To execute the operating system command in the background,
include the trailing character,
&, in the
'emacs &'). The exit status is
immediately returned to the
status variable. This
syntax is useful for console programs that require interactive user
command input while they run, and that do not run correctly in the MATLAB Command
stdin to the invoked command,
by default. This redirection also passes MATLAB script commands and
the keyboard type-ahead buffer to the invoked command while the
executes. This can lead to corrupted output when
not complete execution immediately. To disable
type-ahead redirection, include the formatted string
/dev/null in the call to the invoked command.
MATLAB uses a shell program to execute the given command.
It determines which shell program to use by checking environment variables
on your system. MATLAB first checks the
and if either empty or not defined, then checks
SHELL is also empty or not defined, MATLAB uses