Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2025.0.0 - English


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 if commands 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.

For Scilab on MS Windows, the functions unix_g(), unix_s(), unix_w() and unix_x() are based on dos().

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 — set the value of an environment variable
  • host — executes a Windows, Linux, or MacOS command
  • unix_g — executes some Windows, Linux or MacOS instructions: output in variables
  • powershell — executes a command with the Windows powershell interpreter (Windows only)
  • List of MS Windows exit codes
Report an issue
<< createGUID Windows tools findfileassociation >>

Copyright (c) 2022-2024 (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:
Thu Oct 24 11:13:15 CEST 2024