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:
|
Examples
Using Scilab defined environment variable
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 — 環境変数の値を設定e
- 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 >> |