Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Français - Português - 日本語 -
Справка Scilab >> Input/Output functions > 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,

  • rep is set to "".
  • If the output variable 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 remaining instructions after the erroneous one are ignored.
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

  • unix_s — executes some Windows, Linux or MacOS instructions: output canceled (Silent mode)
  • unix_w — executes some Windows, Linux or MacOS instructions: output in Scilab's console
  • unix_x — executes some Windows, Linux or MacOS instructions: output in a dedicated window
  • host — executes a Windows, Linux, or MacOS command
  • getos — возвращает название операционной системы и версию
  • setenv — set the value of an environment variable
  • powershell — executes a command with the Windows powershell interpreter (Windows only)
  • list of MS Windows exit codes
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Feb 14 15:05:03 CET 2019