Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2026.0.0 - Русский


host

executes a Windows, Linux, or MacOS command

unix

alias de host()

Syntax

[status, stdout, stderr] = host(commands, echo=%f)

Arguments

commands

Single string containing instructions sent to the OS command interpreter.

echo

Optional boolean used to print both stdout and stderr in Scilab's console.

status

Integer, the status code return by the executed command.

stdout

String that contains the standard output of the executed command. When the function is called with two output argument, stdout will contain both stdout and stderr.

stderr

String that contains the standard error of the executed command.

Description

host(…) creates a session of the OS command interpreter (sh on Linux and MacOS, or cmd.exe on Windows), to execute the given command.

host(…) returns both outputs in the same variable when it has been called with two output arguments. It can be useful to maintain the chronological order of logs between stdout and stderr.

By using the optional argument echo=%t, the standard output and error will be printed in Scilab's console during the command execution.

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.
  • When called with 2 or 3 outputs the function will wait for the end of the command execution to return outputs.

Examples

Using Scilab defined environment variable
disp(SCI)
if getos() == "Windows" then
    [stat, stdout] = host("echo %SCI%")
else
    [stat, stdout] = host("echo $SCI")
end
Playing with outputs
// get separated stdout and stderr
[stat, stdout, stderr] = host("echo OK && echo KO 1>&2 && echo END")
// get both outputs keeping chronological order
[stat, stdout] = host("echo OK && echo KO 1>&2 && echo END")
Detached command
// Detach a command to avoid waiting for its end
if getos() == "Windows" then
    host("start /b ping localhost")
else
    host("ping -c 3 localhost &")
end

// But, this command will wait for outputs
if getos() == "Windows" then
    [stat, stdout] = host("start /b ping localhost")
else
    [stat, stdout] = host("ping -c 3 localhost &")
end
Force command outputs in the Scilab's console
if getos() == "Windows" then
    host("ping localhost", echo=%t)
else
    host("ping -c 3 localhost", echo=%t)
end

See also

  • consolebox — shows or hides the MS Windows terminal running the Scilab session
  • getos — возвращает название операционной системы и версию
  • setenv — set the value of an environment variable
  • powershell — executes a command with the Windows powershell interpreter (Windows only)

History

ВерсияОписание
2025.1.0 Returns standard output and standard error.
2026.0.0 An optional named argument 'echo' was added.
Report an issue
<< getpid OS_commands scilab >>

Copyright (c) 2022-2025 (Dassault Systèmes S.E.)
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:
Thu Oct 16 09:11:26 CEST 2025