problem with IF statement

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
chrisg
Newbie
Posts: 3
Joined: Thu May 04, 2006 2:26 pm

problem with IF statement

Post by chrisg » Thu May 04, 2006 3:30 pm

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.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu May 04, 2006 3:46 pm

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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu May 04, 2006 3:52 pm

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

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts