I had a typo, specify:
  lineList = STAFResult.splitlines()

not: 
lineList = STAFResult.splitlines(True)

<stafcmd name = "'Get the result file'"> 
  <location>'local'</location>
 <service>'FS'</service>
 <request>'GET FILE %s TEXT' % resultTxT</request> 
</stafcmd> 

<if expr="RC == 0"> 
  <sequence>
   <log message="1"> 
      'File %s contains %s characters.  File contents:\n%s' % (resultTxT, 
len(STAFResult), STAFResult) 
    </log> 
    <script> 
      noErrors = 0 
      lineList = STAFResult.splitlines()       # Get a list of the lines 
in the file 
      if len(lineList) > 0:                    # Make sure there is at 
least 1 line 
        if lineList[0].startswith('0 error'):  # See if line 1 starts with 
"0 error" 
          noErrors = 1                         # Line 1 starts with "0 
error" 
    </script> 
    <if expr="noErrors"> 
      <log message="1">'0 error'</log> 
      <else> 
        <log message="1">'Errors'</log> 
      </else> 
    </if> 
  </sequence> 
  <else> 
    <log message="1">'Error getting contents of file %s, RC=%s Result=%s' 
% (resultTxT, RC, STAFResult)</log> 
  </else>
</if> 

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313

----- Forwarded by Sharon Lucas/Austin/IBM on 04/27/2011 12:53 PM -----

From:   Sharon Lucas/Austin/IBM@IBMUS
To:     Cindy Zhu <c...@fekete.com>
Cc:     "staf-users@lists.sourceforge.net" 
<staf-users@lists.sourceforge.net>
Date:   04/27/2011 12:51 PM
Subject:        Re: [staf-users] Getting the file contents



STAFResult contains a string containing the contents of the file.  If you 
look at Python documentation for the len() function (just google), you'll 
see that it returns the number of characters in a given string. 

You can also look at Python documentation to find ways to read a string 
line by line or to split up a multi-line string.  For example, the 
splitlines() function is designed to split a multi-line string into a list 
element where each item in the list contains a line in the string. For 
example: 

  STAFResult.splitlines()  # --> ['Line 1', 'Line 2', 'Line 3']

Also, don't specify FORMAT " " on the FS GET FILE TEXT request as that 
changes line ending characters to a blank.  You want the line ending 
characters to be in the string so you can split the string by line ending 
character(s). 

<stafcmd name = "'Get the result file'"> 
  <location>'local'</location>
 <service>'FS'</service>
 <request>'GET FILE %s TEXT' % resultTxT</request> 
</stafcmd> 

<if expr="RC == 0"> 
  <sequence>
   <log message="1"> 
      'File %s contains %s characters.  File contents:\n%s' % (resultTxT, 
len(STAFResult), STAFResult) 
    </log> 
    <script> 
      noErrors = 0 
      lineList = STAFResult.splitlines(True)   # Get a list of the lines 
in the file 
      if len(lineList) > 0:                    # Make sure there is at 
least 1 line 
        if lineList[0].startswith('0 error'):  # See if line 1 starts with 
"0 error" 
          noErrors = 1                         # Line 1 starts with "0 
error" 
    </script> 
    <if expr="noErrors"> 
      <log message="1">'0 error'</log> 
      <else> 
        <log message="1">'Errors'</log> 
      </else> 
    </if> 
  </sequence> 
  <else> 
    <log message="1">'Error getting contents of file %s, RC=%s Result=%s' 
% (resultTxT, RC, STAFResult)</log> 
  </else>
</if> 

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




From:        Cindy Zhu <c...@fekete.com> 
To:        "staf-users@lists.sourceforge.net" 
<staf-users@lists.sourceforge.net> 
Date:        04/27/2011 12:01 PM 
Subject:        [staf-users] Getting the file contents 



Hi,


I use STAF command "Get File" to retrieve the contents of the file

<stafcmd name = "'Parse the result file'">
                                 <location>'local'</location>
                                 <service>'FS'</service>
                                 <request>'GET FILE %s TEXT FORMAT " "' % 
resultTxT</request> 
</stafcmd>
<if expr="RC == 0">
                <log message="1">'Get file successfully, file contains %s 
%s' % (STAFResult, len(STAFResult)<log>
</if> 

what does the function len(STAFResult) return? The total number of 
characters, or the total number of lines?

What I am trying to do is to get the first line of the attach txt file and 
check if it contains string "0 error". Can you suggest what is the best 
way to do it?

Thanks,

Cindy

[attachment "Harmony.txt" deleted by Sharon Lucas/Austin/IBM] 
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to