StdErr Property |
Description
Provides access to the stderr output stream of the IWshExec interface.
PowerBASIC Syntax
Return Value
IDispatch. Reference to a ITextStream interface.
Remarks
Use the StdErr property to retrieve data sent to the stderr stream from a process started with Exec.
Example [PowerBASIC]
The following code demonstrates the StdErr object by attempting to execute a non-existent command and displaying the results.
#COMPILE EXE #DIM ALL #INCLUDE "SCRRUN.INC" #INCLUDE "WSHOM.INC"
FUNCTION ReadAllFromAny (BYVAL pWshExec AS IWshExec) AS STRING
LOCAL pStdOut AS ITextStream LOCAL pStdErr AS ITextStream
pStdOut = pWshExec.StdOut IF ISNOTHING(pStdOut) THEN EXIT FUNCTION
IF ISFALSE pStdOut.AtEndOfStream THEN FUNCTION = ACODE$(pStdOut.ReadAll) EXIT FUNCTION END IF
pStdErr = pWshExec.StdErr IF ISFALSE pStdErr.AtEndOfStream THEN FUNCTION = "STDERR: " & ACODE$(pStdErr.ReadAll) EXIT FUNCTION END IF
END FUNCTION
FUNCTION PBMAIN
LOCAL pWsh3 AS IWshShell3 LOCAL pWshExec AS IWshExec LOCAL strInput AS STRING LOCAL strAllInput AS STRING LOCAL tryCount AS LONG
pWsh3 = NEWCOM "WScript.Shell" IF ISNOTHING(pWsh3) THEN EXIT FUNCTION pWshExec = pWsh3.Exec(UCODE$("%comspec% /c dire"))
DO strInput = ReadAllFromAny(pWshExec) IF strInput = "" THEN IF tryCount > 10 AND pWshExec.Status = 1 THEN EXIT DO tryCount = tryCount + 1 SLEEP 100 ELSE strAllInput = strAllInput & strInput EXIT DO END IF LOOP
STDOUT strAllInput
WAITKEY$
END FUNCTION
|