Re: Help with grep
Re: Help with grep
- Subject: Re: Help with grep
- From: Axel Luttgens <email@hidden>
- Date: Sat, 26 Dec 2015 22:41:25 +0100
> Le 26 déc. 2015 à 19:37, Bert Groeneveld a écrit :
>
> Hello Axel, when I paste your code into a new script it works great! For some reason when I implement it in my main script the handler always returns false. The difference is that in my main script the handler is called from within another handler. Could that be the reason? (I already tried putting the word “my" in front, but that didn’t help.)
Hmmm… There must be a simple/stupid/subtle thing at play here.
My sample check_string() handler lazily assumed that if an error occurs, that’s because no matching string has been found; in such a case, grep would end with a status of 1.
But grep may end with a status code greater then 1, for example when the regular expression is invalid.
Could you try with this version:
on check_string(reg_exp, test_string)
try
do shell script "/usr/bin/grep -E " & quoted form of reg_exp & "<<<" & quoted form of test_string
return true
on error errMsg number errNum
if errNum = 1 then return false
display dialog errMsg & "(" & errNum & ")"
return false
end try
end check_string
and see what gives?
Even better, more info about the possible error cause would be available if you have the opportunity to look at the event log at the same time.
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden