Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
dos
executes some DOS instructions (Windows only)
Syntax
bOK = dos(commands) [output, bOK] = dos(commands) [output, bOK, exitcode] = dos(commands) .. = dos(commands, '-echo')
Arguments
- commands
Single text containing instructions sent to the MS Windows cmd.exe command interpreter.
- '-echo'
Forces the display of results (Windows standard output and error message) in the Scilab console.
- bOK
Single boolean:
%T
ifcommands
has been executed without cmd.exe error,%F
otherwise.- output
Column of text: standard output and standard errors yielded by the MS Windows interpreter.
- exitcode
Integer exit code returned by cmd.exe after completion.
Description
dos()
opens a new session of the MS Windows command interpreter
cmd.exe, sends the 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 current working directory and environment variables of the cmd.exe session are set as described for host().
The standard output and error messages yielded by the OS interpreter are never displayed in the OS terminal running Scilab (the consolebox). They are managed in the following ways:
- If the
output
argument is expected, the standard output and errors messages are returned in it as a column of text. - If the
'-echo'
option is used, the standard output and errors messages are (in addition) displayed in the Scilab console.
Examples
[r, s] = dos('dir'); r [r, s] = dos('dir','-echo'); dos('start notepad') dos('taskkill /IM notepad.exe') // Caution, this command will kill all launched notepad's process [r, s, code] = dos('foo') [r, s, code] = dos('dir')
Current working directory and environment variables in the cmd.exe session:
pwd() // in the Scilab session [r, ok] = dos("cd"); r // in the dos() session setenv TEST AAAA ; // in the Windows interpreter running the Scilab session [r,ok] = dos("echo %TEST%"); r // in the dos() session // Environment variables set in a dos() session are lost when dos() returns: dos("set TEST=BBBB") [r,ok] = dos("echo %TEST%"); r getenv TEST
--> pwd() // in the Scilab session ans = C:\Scilab\tests --> [r, ok] = dos("cd"); r // in the dos() session r = C:\Scilab\tests --> setenv TEST AAAA ; // in the Windows interpreter running the Scilab session --> [r,ok] = dos("echo %TEST%"); r // in the dos() session r = AAAA --> // Environment variables set in a dos() session are lost when dos() returns: --> dos("set TEST=BBBB") ans = T --> [r,ok] = dos("echo %TEST%"); r r = AAAA --> getenv TEST ans = AAAA
See also
- setenv — fixe la valeur d'une variable d'environnement
- host — exécute une commande Windows, Linux, ou MacOS
- unix_g — exécute des instructions Windows, Linux ou MacOS : résultats dans des variables
- powershell — executes a command with the Windows powershell interpreter (Windows only)
- List of MS Windows exit codes
Report an issue | ||
<< createGUID | Outils Windows | findfileassociation >> |