Reputation: 7189
How to redirect Output to a Text file using vb script
I have a code like this
Dim tsIn
set tsIn = goFS.OpenTextFile("E:\..t.csv") 'if file doesn't exist then error
If Err.Number <> 0 Then
MsgBox Err.Description & "Input File Did not open" '> "E:\t.txt"
Exit Sub
End If
But how to redirect the error i get if a file doesn't exist in the folder?
i tried >
but there's no result!
Upvotes: 0
Views: 6477
Reputation: 27491
Redirect error to output. %errorlevel% will still be 0 though.
cscript myscript.vbs > myscript.log 2>&1
Upvotes: 1
Reputation: 5471
Try something like the following
On Error Resume Next
Set objShell = CreateObject("Wscript.Shell")
errTxtFile = objShell.SpecialFolders("Desktop") & "\21777595.txt"
Set objFSO = WScript.CreateObject("Scripting.Filesystemobject")
Set FSO_Handle = objFSO.OpenTextFile (errTxtFile,8,True)
Err.Raise 6 'To test if the error is getting stored or not
If Err.Number <> 0 Then
FSO_Handle.WriteLine Now & " - Error : " & Err.Number & ": " & Err.Description
End If
Upvotes: 1