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

Change language to:
Français - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilab Help >> Windows tools > powershell


executes a command with the Windows powershell interpreter (Windows only)


output = powershell(command)
[output,bOK] = powershell(command)



Single text containing instructions sent to the MS Windows powershell.exe command interpreter.


Column of text: output (and error message) yielded and normally displayed by Powershell on its screen.


Single boolean: %T if command has been executed without error, %F otherwise.


powershell() opens a new session of the MS Windows powershell.exe command interpreter, sends command to it, lets it processing command instructions, receives as text the output and possible error message yielded by the processing, and closes the interpreter session.

The starting current working directory and environment variables of the powershell.exe session are set as described for host().

If an instruction in command generates an error, the error message is caught and returned in output. Nothing is directly displayed neither in the Scilab console nor in the consolebox.

The effects of valid instructions processed before the erroneous one remain actual (for instance, deleted files). However, their valid output is canceled and not returned in output.

Any path included in the command must be single-quoted.


Current directory:

r = powershell("pwd");

// Directory content
path = TMPDIR + "\répertoire test";
mputl("Test of listing", path+"\test.txt");
[r,ok] = powershell("ls ''"+path+"''"); ok   // single quotes ' needed
rmdir(path, "s");

Handling of environment variables, date:

setenv TEST ABCD;

// Current date:
[r,ok] = powershell("get-Date -format ""yyyy-MM-dd HH:mm"""); ok  // => error
[r,ok] = powershell("get-Date -format ''yyyy-MM-dd HH:mm''")
--> setenv TEST ABCD;
--> powershell("$env:TEST")
 ans  =

--> // Current date:
--> [r,ok] = powershell("get-Date -format ""yyyy-MM-dd HH:mm"""); ok
 ok  =

--> [r,ok] = powershell("get-Date -format ''yyyy-MM-dd HH:mm''")
 ok  =
 r  =
 2018-04-30 07:12

Multiple instructions separated with ";":

powershell("echo $env:USERNAME'' uses powershell in Scilab'' ; Get-Date")
--> powershell("echo $env:USERNAME'' uses powershell in Scilab'' ; Get-Date")
 ans  =
!Samuel uses powershell in Scilab  !
!                                  !
!lundi 30 avril 2018 07:21:02      !
!                                  !

See also

  • host — executes a Windows, Linux, or MacOS command
  • dos — executes some DOS instructions (Windows only)
  • unix_g — executes some Windows, Linux or MacOS instructions: output in variables
Report an issue
<< mcisendstring Windows tools win64 >>

Copyright (c) 2022-2023 (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:
Tue Feb 25 08:49:24 CET 2020