1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Stackoverflow]

Discussão em 'StackOverflow' iniciado por fdantas, Setembro 9, 2024.

  1. fdantas

    fdantas Administrator Moderador

    I'm trying to implement a class wrapper around 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.

    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:

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

Compartilhe esta Página