<< setenv OS_commands unix_s >>

Scilab Help >> Input/Output functions > OS_commands > unix_g

unix_g

executes some Windows, Linux or MacOS instructions: output in variables

Syntax

rep = unix_g(commands)
[rep, status] = unix_g(commands)
[rep, status, msgerr] = unix_g(commands)

Arguments

commands

A single text: instruction(s) to be executed

rep

column of text: standard output.

status

an integer, the error status. status=0 if no error occurred

msgerr

column of text: error message.

Description

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,

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.

Examples

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')

See also


Report an issue
<< setenv OS_commands unix_s >>