05-05-2019, 11:48 PM (This post was last modified: 05-06-2019, 12:07 AM by win.)
Powershell syntax is simple, has been updated to 6.x, and the function is getting stronger!It can also call libraries supported by .net
I found a situation, using the pscmd function, after executing the code, the output results always have some fixed, extra characters, very regular, is there a way to display only the results?
Maybe already have a solution, just I don't know, Thanks in advance
extra characters:
first line:
#< CLIXML
last line:
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>
;Executes PowerShell script stored in a variable or macro. ;Waits and returns powershell.exe's return value.
;commands - one or more PowerShell commands. ;;;QM 2.3.5. Can be macro, like "macro:MacroName". Gets whole text, or text that follows #ret line. Ignores first line if it looks like macro options ( /...). ;;;QM 2.3.5. If "", gets caller's text that follows #ret line. ;cl - additional powershell.exe command line arguments. ;output - variable that receives output text. If omitted or 0, displays the text in QM output. ;flags - output text encoding. See example.
;REMARKS ;Uses a temporary file and command line -File to pass it to powershell.exe. Also adds command line -ExecutionPolicy Bypass. ;Error if powershell.exe does not exist. PowerShell is available on Windows 7/2008/+, and can be downloaded for some older Windows versions.
str ps.searchpath("powershell.exe");if(!ps.len)end"PowerShell not installed" str s.format("%s %s" ps cl) if(!&output)int print=1;str so;&output=so int enc=0;if(flags&1) enc=0x800;elseif(flags&2) enc=0x400 int r=RunConsole2(s output 0 enc)
output.trim("[]") if(print and output.len)out output ret r
I don't know why –P is damaged. On my PC works well. I'm using Windows 10 with its PowerShell, don't know which version.
If you have the very first version of PsCmd3, try current version. It marks the file as UTF-8 if QM is in Unicode mode (default). The first version did not support Unicode.
I tested your code with {variable} and it works without errors. Don't know why not on your PC. Result:
{"log_id": 1252041876708167624, "words_result_num": 0, "words_result": []}
05-08-2019, 05:42 AM (This post was last modified: 05-08-2019, 05:57 AM by win.)
Tip in the image upper right corner: File not found
The file path in the image lower left corner seems to be split in two lines.
I think in the Chinese version of the system, it should be escaping \n
I very much hope to solve this problem.
Because I think it is very convenient to use PS to call the .net class library.
PS syntax is simpler than C#, automatic task is completely enough
05-08-2019, 01:05 PM (This post was last modified: 05-08-2019, 01:07 PM by Gintaras.)
It seems you use the old version of PsCmd3. As I wrote previously, it did not support Unicode. Also need flag 1 and OutputEncoding, like in the example in PsCmd3 code.
;Executes PowerShell script stored in a variable or macro. ;Waits and returns powershell.exe's return value.
;commands - one or more PowerShell commands. ;;;QM 2.3.5. Can be macro, like "macro:MacroName". Gets whole text, or text that follows #ret line. Ignores first line if it looks like macro options ( /...). ;;;QM 2.3.5. If "", gets caller's text that follows #ret line. ;cl - additional powershell.exe command line arguments. ;output - variable that receives output text. If omitted or 0, displays the text in QM output. ;flags - output text encoding. See example.
;REMARKS ;Uses a temporary file and command line -File to pass it to powershell.exe. Also adds command line -ExecutionPolicy Bypass. ;Error if powershell.exe does not exist. PowerShell is available on Windows 7/2008/+, and can be downloaded for some older Windows versions.
str ps.searchpath("powershell.exe");if(!ps.len)end"PowerShell not installed" str s.format("%s %s" ps cl) if(!&output)int print=1;str so;&output=so int enc=0;if(flags&1) enc=0x800;elseif(flags&2) enc=0x400 int r=RunConsole2(s output 0 enc)
output.trim("[]") if(print and output.len)out output ret r