如何使用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
但如果文件夹中不存在文件,如何重定向错误?
我试过>
,但没有结果!
答案 0 :(得分:1)
尝试类似以下内容
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
答案 1 :(得分:0)
将错误重定向到输出。 %errorlevel%仍然是0。
cscript myscript.vbs > myscript.log 2>&1