Page 1 of 1 1
Topic Options
#34781 - 2003-01-06 02:24 PM Readline problem
anthonyl Offline
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
#34782 - 2003-01-06 02:32 PM Re: Readline problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The problem is in the fourth line of your script. [Wink]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#34783 - 2003-01-06 02:34 PM Re: Readline problem
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Might want to post your code on this one so we can have a lookie.
Top
#34784 - 2003-01-06 02:35 PM Re: Readline problem
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Your scaring me Les - you using "the force" again ?
Top
#34785 - 2003-01-06 03:06 PM Re: Readline problem
anthonyl Offline
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 Offline
Fresh Scripter

Registered: 2002-11-19
Posts: 12
Loc: Work
By the way the rest of the code works fine, just that readline command [Frown]
Top
#34787 - 2003-01-06 03:16 PM Re: Readline problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I see a couple if things but before I comment, I would like to see a few lines of "sync-c.log" that contain "sending" and "FAILED SEND".
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#34788 - 2003-01-06 03:22 PM Re: Readline problem
anthonyl Offline
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
#34789 - 2003-01-06 03:37 PM Re: Readline problem
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You posted incomplete code as there are a couple of ENDIFs and the LOOP missing.

Try this:
code:
IF Open(1,"c:\sync-c.log") = 0
$currentline = ReadLine(1)
WHILE @ERROR = 0
$lastline=$currentline
$currentline = ReadLine(1)
if instr($lastline,'sending') and instr($currentline,'failed send')
; failed to send
endif
LOOP
Close (1)
endif

_________________________
There are two types of vessels, submarines and targets.

Top
#34790 - 2003-01-06 04:20 PM Re: Readline problem
Richard H. Administrator Offline
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 Offline
Fresh Scripter

Registered: 2002-11-19
Posts: 12
Loc: Work
Richard,

Many thanks, your code works great, I am very impressed.!! [Smile]

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
#34792 - 2003-01-06 04:54 PM Re: Readline problem
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Look up READPROFILESTRING/WRITEPROFILESTRING in the KiXtart Manual.
_________________________
There are two types of vessels, submarines and targets.

Top
#34793 - 2003-01-06 04:58 PM Re: Readline problem
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Writing to a "ini" file is trivial - have a look ad the WriteProfileString() function in the manual.

You might like to elaborate on what you are trying to achieve, otherwise we will not be able to suggest a solution that best fits your requirements.

Top
#34794 - 2003-01-06 05:01 PM Re: Readline problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
In other words give us an example of what you expect the INI to contain.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#34795 - 2003-01-06 05:48 PM Re: Readline problem
anthonyl Offline
Fresh Scripter

Registered: 2002-11-19
Posts: 12
Loc: Work
Sorry for being a lazy sod [Wink] 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 [Smile]

Cheers,

Anthony.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1607 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.099 seconds in which 0.052 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org