Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Debugging capture StdErr capture in script.

82 views
Skip to first unread message

RajW

unread,
Feb 21, 2009, 4:08:29 PM2/21/09
to

I have this command line program from a vendor that unfortunately
sends it error information to StdErr instead of StdOut, so I cannot
use the usual redirect output ( > ) and then scan the generated text
file. So, I was able to use objShell.Exec to execute the command. The
variable objArcItem contains the name of the archive. Example (Line
2):

01 WScript.Echo arccount & ") Scanning file: " & objArcItem
02 Set objExecObject = objShell.Exec("cmd /c e:\dump.exe /archive "
& objArcItem & " /blocks /checkcrc")
03
04 ' Look for the CRC mismatch text in the STDERR output
05 Do While Not objExecObject.StdErr.AtEndOfStream
06 strText = objExecObject.StdErr.ReadLine()
07 WScript.Echo strText
08 If InStr(strText, "CRC mismatch") > 0 Then
09 WScript.Echo "** FAIL ** CRC mismatch"
10 objFail = 1
11 Exit Do
12 End If
13 Loop

The above snipit works for the one file that gets scanned (variable
definitions omitted in the post). The problem is that when I try scan
a collection (code below), it prints the output from line 1 and then
just hangs. Here is the collection code snipit. Line numbers added for
clarity in pointing out wth I did wrong. :)

01 Dim objFSO: Set objFSO =
CreateObject("Scripting.FileSystemObject")
02 Dim objShell: Set objShell = CreateObject("WScript.Shell")
03 Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" &
objNetwork.ComputerName & "\root\CIMV2")
04 Dim arccount : arccount = 1
05 Dim objArcItem
06 Dim colArcFiles
07 Dim objExecObject
08
09 ' Query WMI for a list of all ARC files
10 ' on the E drive
11 '
12 Set colArcFiles = objWMIService.ExecQuery("SELECT * FROM
CIM_DataFile WHERE Drive ='e:' AND Extension = 'arc' AND Path LIKE
'%\\[0-2][0-9]\\%' ", "WQL", _
13 wbemFlagReturnImmediately + wbemFlagForwardOnly)
14
15 ' Run the command
16 ' dump.exe /archive {archive name} /blocks /crc
17 ' on every file in the collection colArcFiles
18 '
19 For Each objArcItem In colArcFiles
20 WScript.Echo arccount & ") Scanning file: " & objArcItem.Name
21 Set objExecObject = objShell.Exec("%comspec% /c e:\dump.exe
/archive " & objArcItem.Name & " /blocks /checkcrc")
22
23 ' Look for the CRC mismatch text in the STDERR output
24 Do While Not objExecObject.StdErr.AtEndOfStream
25 strText = objExecObject.StdErr.ReadLine()
26 WScript.Echo strText
27 If InStr(strText, "CRC mismatch") > 0 Then
28 WScript.Echo "** FAIL ** CRC mismatch"
29 objFail = 1
30 Exit Do
31 End If
32 Loop

Any advice would be appreciated.

Kind regards,
/*Raj*/

Pegasus (MVP)

unread,
Feb 21, 2009, 4:57:43 PM2/21/09
to

"RajW" <n...@way.com> wrote in message
news:mup0q4toc5jfo80qr...@4ax.com...

>
> I have this command line program from a vendor that unfortunately
> sends it error information to StdErr instead of StdOut, so I cannot
> use the usual redirect output ( > ) and then scan the generated text
> file.

This is incorrect. Here are a couple of ways to pick up all stream output:

c:\xxx.exe 1>c:\std.txt 2>c:\err.txt
c:\xxx.exe 1>c:\stream.txt 2>&1

You can now scan c:\err.txt (option 1) or c:\stream.txt (option 2).


RajW

unread,
Feb 21, 2009, 8:34:36 PM2/21/09
to
On Sat, 21 Feb 2009 22:57:43 +0100, "Pegasus \(MVP\)"
<I....@fly.com.oz> wrote:

>This is incorrect. Here are a couple of ways to pick up all stream output:
>
>c:\xxx.exe 1>c:\std.txt 2>c:\err.txt
>c:\xxx.exe 1>c:\stream.txt 2>&1
>
>You can now scan c:\err.txt (option 1) or c:\stream.txt (option 2).

Really? Wow... and I thought I knew DOS. LOL! I learned something new
today. :)

Is there a way to make my WSH program work with the collection as
well?

Thank you for your help.

Kind regards,
/*Raj*/

Pegasus (MVP)

unread,
Feb 22, 2009, 2:48:53 AM2/22/09
to

"RajW" <n...@way.com> wrote in message
news:ipa1q4dlektr1ugbf...@4ax.com...

I would download a copy of script56.chm and scan it for stderr. Lots of
useful stuff in there!


0 new messages