Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - Português

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

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

Ajuda do Scilab >> Funções de Entrada/Saída > OS_commands > host


executes a Windows, Linux, or MacOS command


alias of host()


status = host(commands)

status = unix(commands)



Single text containing Windows, Linux, or MacOS instructions sent to the OS command interpreter.


integer flag: -1 if the commands can't be executed (for instance due to unsufficient memory). If commands is executed (successfully or not) : exit code number returned by the Operating System (OS) interpreter.

With Windows, 0 is most often returned in case of successful execution.



  • creates a session of the OS command interpreter (sh with Linux, or cmd.exe with Windows).
  • sends the given commands to it,
  • lets them be executed by the OS interpreter,
  • receives all the messages normally displayed in the OS interpreter terminal,
  • and closes the OS interpreter session.

The opened session of the OS interpreter is a fork of the session homing the current Scilab session. As a consequence, it has the following properties:
  • Its starting current working directory (CWD) is the current one in the Scilab session when running host(…).
  • Its starting environment variables are copied from the OS interpreter session homing the current Scilab session. They can be modified using setenv, before calling host().
  • Changing the CWD or/and the environment variables with instructions in commands does not change them in the Scilab session or/and in the underlying OS interpreter session homing it.

The host(…) results as standard output and standard errors are written in the terminal from which the Scilab session has been launched (a.k.a. the consolebox for MS Windows)..

host() shall be preferred to its unix() alias, whose name is misleading.
On MS Windows, host("cls") CLears the consolebox Screen.


For Windows users:

Current working directory in the host() and Scilab OS interpreter respective sessions:

pwd     // Current working directory of the Scilab session
if getos()=="Windows"
    host cls;
    consolebox on;
    host cd;        // Starting working directory in the OS interpreter session
    host pwd;
// The paths in the OS terminal/consolebox and in the Scilab console are the same  <<==

Display in the OS terminal (consolebox):

host cls;
host "echo Scilab host() function";
host "echo A & echo BC";
host("echo DEF"+ascii(10)+"echo G");
host("echo Current working directory: & cd");
host dira;   // => error: unknown command
Scilab host() function
Current working directory:
'dira' is not a known internal or external command, executable program, or batch file.

Environment variables in the Scilab and host() sessions:

setenv TEST AAAA;
host cls;
host "echo %TEST%";
host "set TEST=BBBB";
getenv TEST
Display: Rows starting with ":" are displayed in the consolebox, other ones in the Scilab console:
--> setenv TEST AAAA;
 ans  =

--> host cls;
--> host "echo %TEST%";

: Samuel 2

--> host "set TEST=BBBB"  // well done:
 ans  =

--> getenv TEST
 ans  =
Application example:

Portable openURL() function based on host():

function openURL(url)
    if getos()=="Windows"
    elseif getos()=="Linux"
        host("xdg-open """+url+"""")
    elseif getos()=="Darwin"         // Mac OS
        host("open """+url+"""")
        warning("openURL: unknown OS")

// call it:

See also

  • consolebox — shows or hides the MS Windows terminal running the Scilab session
  • getos — retorna o nome e a versão do Sistema Operacional
  • setenv — ajusta o valor de uma variável de ambiente
  • unix_g — executa algumas instruções do Windows, Linux ou MacOS, saída em variáveis
  • unix_s — executa silenciosamente algumas instruções do Windows, Linux ou MacOS
  • unix_w — executa algumas instruções do Windows, Linux ou MacOS, resulta no console do Scilab
  • unix_x — executar algumas instruções do Windows, Linux ou MacOS, resulta em uma janela de mensagem pop-up
  • dos — executes some DOS instructions (Windows only)
  • powershell — executes a command with the Windows powershell interpreter (Windows only)
  • List of MS Windows exit codes
Report an issue
<< getpid OS_commands setenv >>

Copyright (c) 2022-2023 (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:52:31 CET 2020