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
- unix_w
- unix_x
- host
- getos
- setenv
- powershell
- list of MS Windows exit codes