Skip to main content
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
------------------------------
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
------------------------------
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
------------------------------
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
------------------------------

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
------------------------------

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
------------------------------

Hi Harjit,

I agree with you about the issue with powershell;
anyhow as a temporary solution you could pipe your command to redirect the output to a file and reload from that file.

Regards,
Gianni



------------------------------
Gianni Sandigliano
IT
------------------------------


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
------------------------------

Is it a case of requiring channel redirection. 

A powershell script, to run your powershell script  which has something like

./yourscript.ps *>&1

Which should put all channels to the output channel, and make them 'capturable'? 

Iain



------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

Is it a case of requiring channel redirection. 

A powershell script, to run your powershell script  which has something like

./yourscript.ps *>&1

Which should put all channels to the output channel, and make them 'capturable'? 

Iain



------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

Except I notice you've mentioned not being able to capture Write-Output either.... 



------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------