I have to redirect a vbs file through batch-file.
My code is like:
@echo off
echo Option Explicit>> weather.vbs
echo Dim LogFile,Ws,Tag,Content>> weather.vbs
echo LogFile = Left(Wscript.ScriptFullName,InstrRev(Wscript.ScriptFullName, .)) & txt >> weather.vbs
echo Set Ws = CreateObject(wscript.Shell) >> weather.vbs
echo With CreateObject(InternetExplorer.Application) >> weather.vbs
echo .Visible = False>> weather.vbs
echo .Navigate http://aldweathersh2.blogspot.in/ >> weather.vbs
echo Do Until .ReadyState = 4 >> weather.vbs
echo Wscript.Sleep 6000>> weather.vbs
echo Loop>> weather.vbs
echo For Each Tag In .Document.GetElementsByTagName(script) >> weather.vbs
echo Tag.OuterHtml = >> weather.vbs
echo Next>> weather.vbs
echo For Each Tag In .Document.GetElementsByTagName(noscript) >> weather.vbs
echo Tag.OuterHtml = >> weather.vbs
echo Next>> weather.vbs
echo Content = .Document.GetElementsByTagName(body)(0).InnerText >> weather.vbs
echo Do While InStr(Content, vbCrLf & vbCrLf)>>weather.vbs
echo Content = Replace(Content, vbCrLf & vbCrLf, vbCrLf) >> weather.vbs
echo Loop >> weather.vbs
echo WriteLog Content,LogFile >> weather.vbs
echo .Quit>> weather.vbs
echo End With>> weather.vbs
echo '******************************************************************* >> weather.vbs
echo Sub WriteLog(strText,LogFile) >> weather.vbs
echo Dim fso,ts>> weather.vbs
echo Const ForWriting = 2 >> weather.vbs
echo Set fso = CreateObject(Scripting.FileSystemObject) >> weather.vbs
echo Set ts = fso.OpenTextFile (LogFile,ForWriting,True,-1) >> weather.vbs
echo ts.WriteLine strText>> weather.vbs
echo ts.Close>> weather.vbs
echo End Sub>> weather.vbs
echo '******************************************************************>> weather.vbs
pause
Problem occurs with the batch-file while executing strings containing "&" in it. Every time it breaks the redirection with "&".
Error is:
LogFile = Left(Wscript.ScriptFullName,InstrRev(Wscript.ScriptFullName, .))
'txt' is not recognized as an internal or external command,
operable program or batch file.
Do While InStr(Content, vbCrLf
'vbCrLf)' is not recognized as an internal or external command,
operable program or batch file.
Content = Replace(Content, vbCrLf
'vbCrLf' is not recognized as an internal or external command,
operable program or batch file.
Is there any way to also redirect strings with "&" in batch-file ?
Escape the &
(and other problematic characters) with ^
, so
echo Do While InStr(Content, vbCrLf ^& vbCrLf)>>weather.vbs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With