executes some Windows, Linux or MacOS instructions: output in variables
rep = unix_g(commands) [rep, status] = unix_g(commands) [rep, status, msgerr] = unix_g(commands)
A single text: instruction(s) to be executed
column of text: standard output.
an integer, the error status. status=0 if no error occurred
column of text: error message.
unix_g(…)
opens a new session of the Operating System (OS) command
interpreter (sh with Linux, cmd.exe with
Windows, etc..), sends commands
to it,
lets it processing commands
instructions, receives the standard
output and possible error message yielded by the processing, and closes the interpreter
session.
The starting working directory and environment variables of the opened interpreter are set as described for host().
The standard output is recorded in the variable rep
.
If commands
includes an erroneous instruction,
rep
is set to "".msgerr
is used, the error message normally
displayed in the OS terminal is caught and stored in it. Otherwise, the OS error
is displayed in the Scilab console.![]() | The effects of valid instructions processed before the erroneous one remain actual
(for instance, deleted files). However, their standard output is lost.
This is why multiple instructions in commands are not recommended. |
function d=DIR(path) path = pathconvert(path,%t,%t) if getos() == 'Windows' then d = unix_g('dir '+path) else d = unix_g('ls '+path) end endfunction DIR('SCI/etc') | ![]() | ![]() |