Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - English

Change language to:
Français - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

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,

  • 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 — return Operating System name and version
  • 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
Report an issue
<< setenv OS_commands unix_s >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:49:20 CET 2020