Original Message:
Sent: 02-15-2023 09:04
From: Harjit Batra
Subject: Capture Powershell output using CommandOut
I don't think my original question was understood. I am looking to capture the output of a Powershell command or script via the commandout method. I already know how to capture the output of a Windows Shell command - commands like dir, type, sort etc send their output to stdout and the ComandOut has no issue grabbing the output sent to stdout from these commands. However when you attempt to run Powershell.exe directly or under the control of a "cmd /c", any output created by the Write-Host or Write-Output from within the Powershell session does not appear to be captured by the CommandOut method and THAT is the issue I am trying to resolve.
Actually, it appears that trying to run Powershell directly (i.e. without the cmd /c start /wait /b /min "" prefix) does not even run either Powershell or the command or script file that follows, however that is a separate problem in itself.
------------------------------
Harjit Batra
IT Director
Rohrer Corporation
Original Message:
Sent: 02-08-2023 08:44
From: Osman Shariff
Subject: Capture Powershell output using CommandOut
This may be an option:-
It is a bit chopped up, but the idea is there.... It takes the output from a dos command (git current branch).
Compares the output and returns a variable errorlevel.
Uniface then gets this.
ignore the sPct and sX... They are just problems I had with %age in uniface.
sPct = "%%""sX = "%x%";; Is it already the correct branch errorlevel=9(already on branch)putitem sScriptPut, -1, "for /f %%"usebackq tokens=*%%" %% i in (`%%"%%$SGIT$%%%%%" rev-parse --abbrev-ref HEAD`) DO set x=%% i"putitem sScriptPut, -1, "IF %%sPct%%%%%sX%%%%%sPct%%% == %%"%%pBranch%%%%%" Set errorlevel=9"putitem sScriptPut, -1, "echo HERE=%ERRORLEVEL%"......activate "OS".COMMANDOUT("{filename}", sOutput)scan sOutput, "HERE="if ($status = 0) nStart = $result + 5 nError = $number(sOutput[nStart:4])endif
------------------------------
Osman Shariff
Original Message:
Sent: 02-07-2023 15:52
From: Harjit Batra
Subject: Capture Powershell output using CommandOut
While it seems pretty simple to capture the output of a Windows command using the CommandOut method of the OS signature, it appears that it not possible to capture the output of Powershell commands such as Write-Host or Write-Output, without first sending the output to a text file and then using a Windows command to read, display and capture the output via CommandOut in Uniface.
Has anyone resolved this issue and managed to capture Powershell output directly and how?
------------------------------
Harjit Batra
IT Director
Rocket Forum Shared Account
------------------------------