host
executes a Windows, Linux, or MacOS command
unix
alias of host()
Syntax
status = host(commands)
status = unix(commands)
Arguments
- commands
Single text containing Windows, Linux, or MacOS instructions sent to the OS command interpreter.
- status
integer flag: -1 if the
commands
can't be executed (for instance due to unsufficient memory). Ifcommands
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.
Description
host(…)
- 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:
|
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. |
Examples
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 else host pwd; end // 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 A BC DEF Current working directory: C:\Scilab\tests '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; getenv NUMBER_OF_PROCESSORS host cls; host "echo %TEST%"; host "echo %USERNAME% %NUMBER_OF_PROCESSORS%"; host "set TEST=BBBB"; getenv TEST
--> setenv TEST AAAA; --> getenv NUMBER_OF_PROCESSORS ans = 2 --> host cls; --> host "echo %TEST%"; : AAAA --> host "echo %USERNAME% %NUMBER_OF_PROCESSORS%"; : Samuel 2 --> host "set TEST=BBBB" // well done: ans = 0. --> getenv TEST ans = AAAA
Application example:
Portable openURL() function based on host():
See also
- consolebox — shows or hides the MS Windows terminal running the Scilab session
- getos — オペレーティングシステムの名前とバージョンを返す
- setenv — 環境変数の値を設定e
- unix_g — いくつかのWindows、LinuxまたはMacOS命令を実行し、変数で出力する
- unix_s — Windows、LinuxまたはMacOSの命令を静かに実行する
- unix_w — いくつかのWindows、LinuxまたはMacOS命令を実行し、結果をScilabコンソールに表示する
- unix_x — いくつかのWindows、LinuxまたはMacOS命令を実行する: 結果はポップアップメッセージボックスに表示される
- 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 >> |