使用批处理文件编写文件时遇到问题。似乎一个字符正在触发这样的回声结束:代码是一个下载器。
C:\ProgramData\Tempfolder\test.vbs ECHO if WScript.Arguments.Count < 1 then
但文件输出是这样的。
if WScript.Arguments.Count then
这是我的代码:
mkdir C:\ProgramData\Tempfolder
>> C:\ProgramData\Tempfolder\test.vbs ECHO if WScript.Arguments.Count <1 then
>> C:\ProgramData\Tempfolder\test.vbs ECHO MsgBox "Usage: wget.vbs <url> (file)"
>> C:\ProgramData\Tempfolder\test.vbs ECHO WScript.Quit
>> C:\ProgramData\Tempfolder\test.vbs ECHO end if
>> C:\ProgramData\Tempfolder\test.vbs ECHO URL = WScript.Arguments(0)
>> C:\ProgramData\Tempfolder\test.vbs ECHO if WScript.Arguments.Count > 1 then
>> C:\ProgramData\Tempfolder\test.vbs ECHO saveTo = WScript.Arguments(1)
>> C:\ProgramData\Tempfolder\test.vbs ECHO else
>> C:\ProgramData\Tempfolder\test.vbs ECHO parts = split(url,"/")
>> C:\ProgramData\Tempfolder\test.vbs ECHO saveTo = parts(ubound(parts))
>> C:\ProgramData\Tempfolder\test.vbs ECHO end if
>> C:\ProgramData\Tempfolder\test.vbs ECHO Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
>> C:\ProgramData\Tempfolder\test.vbs ECHO objXMLHTTP.open "GET", URL, false
>> C:\ProgramData\Tempfolder\test.vbs ECHO objXMLHTTP.send()
>> C:\ProgramData\Tempfolder\test.vbs ECHO If objXMLHTTP.Status = 200 Then
>> C:\ProgramData\Tempfolder\test.vbs ECHO Set objADOStream = CreateObject("ADODB.Stream")
>> C:\ProgramData\Tempfolder\test.vbs ECHO objADOStream.Open
>> C:\ProgramData\Tempfolder\test.vbs ECHO objADOStream.Type = 1 'adTypeBinary
>> C:\ProgramData\Tempfolder\test.vbs ECHO objADOStream.Write objXMLHTTP.ResponseBody
>> C:\ProgramData\Tempfolder\test.vbs ECHO objADOStream.Position = 0 'Set the stream position to the start
>> C:\ProgramData\Tempfolder\test.vbs ECHO Set objFSO = Createobject("Scripting.FileSystemObject")
>> C:\ProgramData\Tempfolder\test.vbs ECHO If objFSO.Fileexists(saveTo) Then objFSO.DeleteFile saveTo
>> C:\ProgramData\Tempfolder\test.vbs ECHO Set objFSO = Nothing
>> C:\ProgramData\Tempfolder\test.vbs ECHO objADOStream.SaveToFile saveTo
>> C:\ProgramData\Tempfolder\test.vbs ECHO objADOStream.Close
>> C:\ProgramData\Tempfolder\test.vbs ECHO Set objADOStream = Nothing
>> C:\ProgramData\Tempfolder\test.vbs ECHO End if
>> C:\ProgramData\Tempfolder\test.vbs ECHO Set objXMLHTTP = Nothing
>> C:\ProgramData\Tempfolder\test.vbs ECHO WScript.Quit
start C:\ProgramData\Tempfolder\test.vbs (link goes here )
而整个回声输出就是这个
if WScript.Arguments.Count then <---- some numbers are missing
MsgBox "Usage: wget.vbs <url> (file)"
WScript.Quit
end if
URL = WScript.Arguments(0) <------- 1 line is missing
saveTo = WScript.Arguments(1)
else
parts = split(url,"/")
saveTo = parts(ubound(parts))
end if
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objXMLHTTP.open "GET", URL, false
objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start
Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(saveTo) Then objFSO.DeleteFile saveTo
Set objFSO = Nothing
objADOStream.SaveToFile saveTo
objADOStream.Close
Set objADOStream = Nothing
End if
Set objXMLHTTP = Nothing
WScript.Quit
如您所见,回声文本中缺少一行。是否有某种开始和结束字符,所以我可以回应这些命令?
如果有人能回答我的问题,我会很高兴。
您正在编写正在编写vbs文件的批处理文件。只需编写VBS文件并运行即可。
—
EBGreen 2015年
您是否尝试转义>或<字符,如下所示:^>或^ <(对于进入vbs脚本的部分)
—
Jared Allard 2015年