Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Français - Português - Русский
Scilabヘルプ >> 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 — いくつかのWindows、LinuxまたはMacOS命令を実行し、変数で出力する
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:53:30 CET 2020