Provides access to the stderr output stream of the Exec object.
Object.StdErr
Use the StdErr property to retrieve data sent to the stderr stream from a process started with Exec.
The following code demonstrates the StdErr object by attempting to execute a non-existent command and displaying the results.
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("%comspec% /c dire")
Function ReadAllFromAny(oExec)
If Not oExec.StdOut.AtEndOfStream Then
ReadAllFromAny = oExec.StdOut.ReadAll
Exit Function
End If
If Not oExec.StdErr
.AtEndOfStream Then
ReadAllFromAny = "STDERR: " + oExec.StdErr.ReadAll
Exit Function
End If
ReadAllFromAny = -1
End Function
Dim allInput, tryCount
allInput = ""
tryCount = 0
Do While True
Dim input
input = ReadAllFromAny(oExec)
If -1 = input Then
If tryCount > 10 And oExec.Status = 1 Then
Exit Do
End If
tryCount = tryCount + 1
WScript.Sleep 100
Else
allInput = allInput & input
tryCount = 0
End If
Loop
WScript.Echo allInput
var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("%comspec% /c dire");
function ReadAllFromAny(oExec)
{
if (!oExec.StdOut.AtEndOfStream)
return oExec.StdOut.ReadAll();
if (!oExec.StdErr.AtEndOfStream)
return "STDERR: " + oExec.StdErr.ReadAll();
return -1;
}
var allInput = "";
var tryCount = 0;
while (true)
{
var input = ReadAllFromAny(oExec);
if (-1 == input)
{
if (tryCount++ > 10 && oExec.Status == 1)
break;
WScript.Sleep(100);
}
else
{
allInput += input;
tryCount = 0;
}
}
WScript.Echo(allInput);