#34781 - 2003-01-06 02:24 PM
Readline problem
|
anthonyl
Fresh Scripter
Registered: 2002-11-19
Posts: 12
Loc: Work
|
Hi there,
I am having a problem with reading lines from a text file.
Basically I read a line and look for "sending " in the line. If "sending " is found I go into a nested IF, ENDIF that reads the next line of the file and then checks for "Failed send".
For some reason the 2nd readline returns a blank line so that "failed send" is never found. If I do 2 consecutive readlines it reads the line but I end up only reading every other line.
Any clues as to why readline would return a blank line (other than the line being blank of course) :-)
Regards,
Anthony
|
|
Top
|
|
|
|
#34785 - 2003-01-06 03:06 PM
Re: Readline problem
|
anthonyl
Fresh Scripter
Registered: 2002-11-19
Posts: 12
Loc: Work
|
here is a snippet...
code:
IF Open(1,"c:\sync-c.log") = 0 Endif $line = Readline(1) WHILE @ERROR = 0 $line = Readline(1) IF substr($line,1,8)='sending ' $prevline=$line $line=substr($line,9) $dot=instr($line,'.') $line=substr($line,1,$dot + 3) $sentfile=$line $line5 = Readline(1) <--Returns a blank line
if substr($line5,1,11)='FAILED SEND' $failfile=$sentfile
The idea is to loop through the file (the loop command is in the full code).
|
|
Top
|
|
|
|
#34786 - 2003-01-06 03:12 PM
Re: Readline problem
|
anthonyl
Fresh Scripter
Registered: 2002-11-19
Posts: 12
Loc: Work
|
By the way the rest of the code works fine, just that readline command
|
|
Top
|
|
|
|
#34788 - 2003-01-06 03:22 PM
Re: Readline problem
|
anthonyl
Fresh Scripter
Registered: 2002-11-19
Posts: 12
Loc: Work
|
Sure, no problem. The following text is taken from a test log I have that includes 4 files that were sent ok, 4 files that were received ok, and 4 files that failed to send.
sending 9372410_ASC_DfESXXX_001.ERR (new file) sending 9372410_ASC_DfESXXX_001.NUM (new file) sending 9372410_ASC_DfESXXX_001.SUM (new file) sending 9372410_ASC_DfESXXX_001.XML (new file) receiving KSM12410.MTF (new file) receiving SEN2410.CSV (new file) receiving BLLIT241.TXT (new file) receiving BLMAT241.TXT (new file) sending ims_archive.bat (new file) FAILED SEND ims_archive.bat HOST:425 Can't open data connection. DLL:425 Can't open data connection. sending IMS_Sync.lnk (new file) FAILED SEND IMS_Sync.lnk HOST:425 Can't open data connection. DLL:425 Can't open data connection. sending ims_transfer.bat (new file) FAILED SEND ims_transfer.bat HOST:425 Can't open data connection. DLL:425 Can't open data connection. sending archive.kix (new file) FAILED SEND archive.kix HOST:425 Can't open data connection. DLL:425 Can't open data connection. # Completed.
|
|
Top
|
|
|
|
#34790 - 2003-01-06 04:20 PM
Re: Readline problem
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
The script below produces this output: quote: Status OK when sending 9372410_ASC_DfESXXX_001.ERR (new file) Status OK when sending 9372410_ASC_DfESXXX_001.NUM (new file) Status OK when sending 9372410_ASC_DfESXXX_001.SUM (new file) Status OK when sending 9372410_ASC_DfESXXX_001.XML (new file) Status OK when receiving KSM12410.MTF (new file) Status OK when receiving SEN2410.CSV (new file) Status OK when receiving BLLIT241.TXT (new file) Status OK when receiving BLMAT241.TXT (new file) Failed when sending file ims_archive.bat (new file). Error follows: : HOST:425 Can't open data connection. : DLL:425 Can't open data connection. Failed when sending file IMS_Sync.lnk (new file). Error follows: : HOST:425 Can't open data connection. : DLL:425 Can't open data connection. Failed when sending file ims_transfer.bat (new file). Error follows: : HOST:425 Can't open data connection. : DLL:425 Can't open data connection. Failed when sending file archive.kix (new file). Error follows: : HOST:425 Can't open data connection. : DLL:425 Can't open data connection.
Here is the code:
code:
$sLogFile="C:\sync-c.log" $fdLogFile=1 $iLine=0 If Open($fdLogFile,$sLogFile) "Error opening file " $sLogFile ? @ERROR ": " @SERROR ? Exit 1 EndIf $sLogEntry=Readline($fdLogFile) While @ERROR=0 $iLine=$iLine+1 $sKeyWord=Split($sLogEntry)[0] Select Case $sLogEntry="" OR $sKeyWord="#" ; Ignore blank lines Case $sKeyWord="sending" OR $sKeyWord="receiving" If $sMode<>"" "Status OK when " $sMode " " $sFile ? EndIf $sFile=SubStr($sLogEntry,Len($sKeyWord)+2) $sMode=$sKeyWord Case $sKeyWord="FAILED" "Failed when " $sMode " file " $sFile ". Error follows:" ? $sMode="" Case "True" If $sMode="" " : " $sLogEntry ? Else "Log file parse error line " $iLine " : Unknown log file entry:" $sLogEntry ? EndIf EndSelect $sLogEntry=Readline($fdLogFile) Loop
|
|
Top
|
|
|
|
#34791 - 2003-01-06 04:46 PM
Re: Readline problem
|
anthonyl
Fresh Scripter
Registered: 2002-11-19
Posts: 12
Loc: Work
|
Richard,
Many thanks, your code works great, I am very impressed.!!
What would be the easyist way to send all the info created to a separate log file called synclog.ini that I can display when the check is complete?
Many many thanks!
Anthony.
|
|
Top
|
|
|
|
#34795 - 2003-01-06 05:48 PM
Re: Readline problem
|
anthonyl
Fresh Scripter
Registered: 2002-11-19
Posts: 12
Loc: Work
|
Sorry for being a lazy sod and you were right to throw the old RTFM at me....anyway I have sorted it now.
Again, many thanks to all contributers, however sarcastic
Cheers,
Anthony.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1607 anonymous users online.
|
|
|