Hi,

Note that you are using the following:

<if expr="'fail'">

You have the expr value in a double set of quotes, so you are telling
Python to evaluate a literal string 'fail', which will always evaluate to
true, and that is why you are always getting "No string is found".  Also,
you need to check if the value returned from re.search is None, indicating
that the pattern was not found.

The following works for me:

<if expr="fail == None">

>From the Python documentation:

re.search(pattern, string[, flags])


      Scan through string looking for a location where the regular
      expression pattern produces a match, and return a corresponding
      MatchObject instance. Return None if no position in the string
      matches the pattern; note that this is different from finding a
      zero-length match at some point in the string.

Thanks,
David


                                                                       
 David Bender          11501 Burnet Rd.   Phone (T/L): 1-512-286-5315  
 STAF/STAX Development Bldg. 903-5B002    (363-5315)                   
                       Austin, TX         ITN: 23635315                
 IBM Software Group,   78758-3400         Email: bda...@us.ibm.com     
 WPLC                                                                  
                                                                       
                                                                       






                                                                       
  From:       Cindy Zhu <c...@fekete.com>                              
                                                                       
  To:         "staf-users@lists.sourceforge.net" 
<staf-users@lists.sourceforge.net>
                                                                       
  Date:       03/01/2011 10:55 PM                                      
                                                                       
  Subject:    [staf-users] Searching a string in a STAX job            
                                                                       





Hi,

I have the following code to search a sting in my STAX job. It is always
failed. Can you please help me out?

<stafcmd name="'Update Silk Include File'">
         <location>"10.0.7.252"</location>
         <service>'FS'</service>
         <request>'GET FILE
"D:/Silk/Apps/Harmony/Include_Harmony.inc"'</request>
</stafcmd>
<script>
import re
result=STAFResult
str_to_find='const STRING WORKING_DIR = "O:/FAST/Harmony/{VERSIONSTRING}/'
str_to_replace='C:/Program Files (x86)/Fekete/Harmony 2011/'
fail=re.search(str_to_find, result)
</script>
<if expr="'fail'">
                <log message="1">'No string is  found %s' %
STAFResult</log>
<else>
                <log message="1">'%s is found' % STAFResult</log>
</else>
</if>


Thanks,

Cindy
 [attachment "Include_Harmony.inc" deleted by David Bender/Austin/IBM]
------------------------------------------------------------------------------

Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT
data
generated by your applications, servers and devices whether physical,
virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

<<inline: graycol.gif>>

<<inline: ecblank.gif>>

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to