system -- execute a command of
the operating system
Introductionsystem("command") executes a command of
the operating system or a program, respectively.
Call(s)system("command")
!command
Parameters"command" |
- | a command of the operating system or a name of a program as a MuPAD character string |
Returnsthe ``error code'': an integer.
Related
Functions
Details!command is almost equivalent to
system("command"); however,
!command does not return any value to the MuPAD
session.system is not available in all MuPAD versions.
In particular, versions running under a Windows operating system do not
support this function. If not available, a call to system
results in the following error message:
Error: Function not available for this client
[system].
system("command") sends the command to
the operating system. E.g., this command may start another application
program on the computer. The return value 0 indicates that
the command was executed successfully. Otherwise, an integer error code
is returned which depends on the operating system and the command.stderr on UNIX
systems, the output will go to MuPAD's stderr. If
system is called in XMuPAD, the output will be
redirected to the shell which called XMuPAD.system is a function of the system kernel.
Example
1On a UNIX or Linux system, the date command
is executed. The command output is printed to the screen, the error
code 0 for successful execution is returned to the
MuPAD session:
>> errorcode := system("date"):
Fri Sep 29 14:42:13 MEST 2000
>> errorcode
0
Now the date command is called with the
command line option '+%m' in order to display the current
month only:
>> errorcode := system("date '+%m'"):
09
Missing the prefix '+' in the command line
option of date, date and therefore
system returns an error code. Note that the error output
goes to stderr:
>> system("date '%m'")
date: invalid date '%m'
1
>> delete errorcode:
Example
2The output of a program started with the
system command cannot be accessed in MuPAD
directly, but it can be redirected into a file and then be read using
the read or ftextinput command:
>> system("echo communication example > comm_file"):
ftextinput("comm_file")
"communication example"
>> system("rm -f comm_file"):