I'm trying to evaluate the content of a text file, but for some reason my IF statement does not want to work. It works with ##EOF## but not with the text string I'm using. Here's my code:
// Let>RP_WINDOWMODE=0
Run Program>c:\vpntest\pinger.bat
wait>15
Let>k=4
Label>start
ReadLn>c:\vpntest\pingresult.txt,k,line
// Message>line - this always shows the correct text in the file
// let>line = "Request timed out." -statement fails even when hardcoded
If>line=##EOF##
macro>%SCRIPT_DIR%\LaunchVPN.scp
finish
endif
IF>%line% = "Request timed out."
macro>%SCRIPT_DIR%\LaunchVPN.scp
finish
endif
IF>%line% = "Ping request could not find host tern. Please check the name and try again."
macro>%SCRIPT_DIR%\LaunchVPN.scp
else
finish
endif
The contents of pinger.bat are very simple:
ipconfig /flushdns
ping tern >c:\vpntest\pingresult.txt
The objective is to ping a remote host over the VPN. If the VPN goes down, then execute the macro to reconnect. The content of the text file works, and when I hardcode the %line% with the correct informsation, the IF statement still does not work properly.
Thanks for your help.
problem with IF statement
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Hi,
Remove the spaces. You need this:
IF>line=Request timed out.
and
IF>line=Ping request could not find host tern. Please check the name and try again.
You also don't want the quotes, unless these are in the actual string. I assume they're not so have removed them.
Remove the spaces. You need this:
IF>line=Request timed out.
and
IF>line=Ping request could not find host tern. Please check the name and try again.
You also don't want the quotes, unless these are in the actual string. I assume they're not so have removed them.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Again, I see spaces where you don't want them. In Macro Scheduler a space is a character, its not like DOS where spaces are ignored.
Your line:
IF>%line% = "Request timed out."
Is actually saying:
If the value of the variable line plus a space, is equal to the text string space quote Request timed out period quote
In other words, every character is significant. If the string in the file c:\vpntest\pingresult.txt does not have quotes around it, don't use the quotes around Request timed out. If it does not have the period, do not use the period. It must exactly match the text in the variable "line" or it is not a match and the If> statement will fail.
Also, rather that wait 15 seconds for thebatch file to run, why not use;
Let>RP_WAIT=1
Which will pause the script until the batch file completes.
Edit---
I see Marcus types faster than I do.
Hope this helps,
Dick
Your line:
IF>%line% = "Request timed out."
Is actually saying:
If the value of the variable line plus a space, is equal to the text string space quote Request timed out period quote
In other words, every character is significant. If the string in the file c:\vpntest\pingresult.txt does not have quotes around it, don't use the quotes around Request timed out. If it does not have the period, do not use the period. It must exactly match the text in the variable "line" or it is not a match and the If> statement will fail.
Also, rather that wait 15 seconds for thebatch file to run, why not use;
Let>RP_WAIT=1
Which will pause the script until the batch file completes.
Edit---
I see Marcus types faster than I do.
Hope this helps,
Dick