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
ifcommand
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
Report an issue | ||
<< mcisendstring | Ferramentas Windows | win64 >> |