执行wScript的VBScript未正确执行
为了将IIS日志自动加载到MSSQL中,我编写了以下函数 执行此函数会导致弹出cmd提示符以执行logparser.exe,然后它会立即关闭。它打开的时间足够长,我可以看到logparser帮助菜单 但是,如果我删除“>>test.out”部分,它将按预期工作执行wScript的VBScript未正确执行,vbscript,wsh,Vbscript,Wsh,为了将IIS日志自动加载到MSSQL中,我编写了以下函数 执行此函数会导致弹出cmd提示符以执行logparser.exe,然后它会立即关闭。它打开的时间足够长,我可以看到logparser帮助菜单 但是,如果我删除“>>test.out”部分,它将按预期工作 Function RunLogParser(logFile) Dim oShell, iRC, ShellString WScript.Echo "Importing File " + logFile + vbCrLf Sh
Function RunLogParser(logFile)
Dim oShell, iRC, ShellString
WScript.Echo "Importing File " + logFile + vbCrLf
ShellString = """C:\Program Files\Log Parser 2.2\LogParser.exe"" ""SELECT * INTO weblog FROM " + logFile + """ " + " -i:W3C -o:SQL -server:localhost -database:testdb -driver:""SQL Server"" -createTable:OFF" + " >> test.out"
WScript.Echo vbTab + "Shell String " + ShellString + vbCrLf
Set oShell = WScript.CreateObject("WScript.Shell")
iRC = oShell.Run(Shellstring, 1, True)
RunLogParser = (iRC=0)
RunLogParser = False
End Function
知道为什么吗?正如你看到的,我正在输出shell字符串,它按照预期的格式正确地输出
Function RunLogParser(logFile)
Dim oShell, iRC, ShellString
WScript.Echo "Importing File " + logFile + vbCrLf
ShellString = """C:\Program Files\Log Parser 2.2\LogParser.exe"" ""SELECT * INTO weblog FROM " + logFile + """ " + " -i:W3C -o:SQL -server:localhost -database:testdb -driver:""SQL Server"" -createTable:OFF" + " >> test.out"
WScript.Echo vbTab + "Shell String " + ShellString + vbCrLf
Set oShell = WScript.CreateObject("WScript.Shell")
iRC = oShell.Run(Shellstring, 1, True)
RunLogParser = (iRC=0)
RunLogParser = False
End Function
要使用shell功能(>>重定向),您需要一个shell;因此,在外壳字符串前加上“%comspec%/c”。由于此命令的复杂性,可能需要进一步修改引号。请尝试使用wsriptPlease的cscript instand提供一个示例?我尝试了这个方法,但没有成功:ShellString=“%comspec%/c”+”c:\Program Files\Log Parser 2.2\LogParser.exe