[英]How to redirect error to a Text file in VBS
如何使用VB腳本將輸出重定向到文本文件
我有這樣的代碼
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
但是,如果文件夾中不存在文件,如何重定向出現的錯誤?
我試過>
但沒有結果!
試試下面的東西
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
將錯誤重定向到輸出。 雖然%errorlevel%仍為0。
cscript myscript.vbs > myscript.log 2>&1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.