W
W0lfw00ds
Guest
I'm trying to implement a class wrapper around
BLOCK-LEVEL ON ERROR UNDO, THROW.
Usage:
Continue reading...
Powershell
. It almost works, except that it hangs when it cannot read any more output from the STREAM
. So it manages to read all output, but after theres no more, it just hangs in IMPORT
statement:BLOCK-LEVEL ON ERROR UNDO, THROW.
Code:
CLASS Powershell:
DEF PRIVATE STREAM stPowershell.
CONSTRUCTOR PUBLIC Powershell():
INPUT-OUTPUT STREAM stPowershell THROUGH VALUE("powershell").
THIS-OBJECT:ReadOutput().
END.
DESTRUCTOR Powershell():
INPUT-OUTPUT STREAM stPowershell CLOSE.
END.
METHOD PUBLIC CHAR Input(i_cInput AS CHAR):
IF i_cInput = ? THEN UNDO, THROW NEW Progress.Lang.AppError(SUBST("&1: 'i_cInput' is 'UNKNOWN'!", PROGRAM-NAME(1))).
PUT STREAM stPowershell UNFORMATTED i_cInput SKIP.
RETURN THIS-OBJECT:ReadOutput().
END.
METHOD PROTECTED CHAR ReadOutput():
DEF VAR cOutputs AS CHAR NO-UNDO.
DEF VAR cOutput AS CHAR NO-UNDO.
DEF VAR lFirst AS LOGICAL NO-UNDO INIT TRUE.
REPEAT:
IF lFirst THEN lFirst = FALSE.
ELSE cOutputs = cOutputs + "~n".
IMPORT STREAM stPowershell UNFORMATTED cOutput NO-ERROR.
cOutputs = cOutputs + cOutput.
END.
RETURN cOutputs.
END.
END.
Usage:
Code:
DEF VAR oPowershell AS CLASS Powershell NO-UNDO.
DEF VAR cOutput AS CHAR NO-UNDO.
oPowershell = NEW Powershell().
cOutput = oPowershell:Input("$num = 12").
cOutput = oPowershell:Input("(New-Object -ComObject Wscript.Shell).Popup($num, 0, 'Done', 0x0)").
cOutput = oPowershell:Input("Write-Output 'test output'").
Continue reading...