matlab_os


matlab_os, a MATLAB code which issues a command to the computer operating system (OS), and collects the results. This is one way that, for instance, MATLAB can continue running, but start up an external executable program that carries out some useful task. For example, MATLAB might create a file, the program might modify it, and MATLAB might use the results.

The call to the operating system has the form

[ status, string ] = system ( command )
where

For example, while running MATLAB, a UNIX user might issue the command

[ status, string ] = system ( 'who' );
and a Microsoft Windows user might issue the command
[ status, string ] = system ( 'dir' );

On a Unix system, the user may use the unix command, and on a PC running Windows, the dos command may be issued. In the case of a dos command, it may be useful to terminate the quoted string with an ampersand, in which case the console will open in a separate window.

If the status and printed output of the system command are of no interest, it is possible to run the command simply using the exclamation mark followed by the command. It is not necessary in this case to put quotes around the command.

For example, while running MATLAB, a UNIX user might issue the command

! who
and a Microsoft Windows user might issue the command
! dir

Since a user's compiled program can be treated as another system command, a MATLAB user might want to run the program a.out while pausing (but not terminating) the MATLAB session. In this way, the a.out program might be able to read files that MATLAB produced, and produce new files that the MATLAB user will need. If the program a.out is in the right place, the command might be as simple as

[ status, string ] = system ( 'a.out' );
or, perhaps
! a.out
or, if input and output files need to be named:
[ status, string ] = system ( 'a.out < input > output' );
or, perhaps
! a.out < input > output

Licensing:

The computer code and data files described and made available on this web page are distributed under the MIT license

Languages:

matlab_os is available in a MATLAB version.

Related Data and Programs:

matlab_calls_c, MATLAB codes which call a C function using the MEX facility.

matlab_commandline, MATLAB codes which illustrate how MATLAB can be run from the UNIX command line, that is, not with the usual MATLAB command window.

matlab_movies, MATLAB codes which generate animations.

matlab_test, MATLAB codes which illustrate some common operations.

Reference:

Examples:

BANG_WHO is an example in which the "bang" command (exclamation mark) is used to invoke the (Unix) system command who.

DOS_DIR is an example in which the dos command is used to invoke the (MS/DOS) system command dir.

SYSTEM_MORE is an example in which the system command is used to invoke the (Unix or MS/DOS) system command more.

UNIX_HEAD is an example in which the unix command is used to invoke the (Unix) system command head.


Last revised on 19 July 2006.