Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.2 - 日本語

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

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

Scilabヘルプ >> Windows tools > powershell

powershell

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

Syntax

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

Arguments

command

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

output

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

bOK

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

Description

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.

Examples

Current directory:

r = powershell("pwd");
r(4)

// Directory content
path = TMPDIR + "\répertoire test";
mkdir(path);
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;
powershell("$env:TEST")

// 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  =
 ABCD


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

--> [r,ok] = powershell("get-Date -format ''yyyy-MM-dd HH:mm''")
 ok  =
  T
 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命令を実行し、変数で出力する
Report an issue
<< mcisendstring Windows tools win64 >>

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 Feb 14 15:02:38 CET 2019