Using FoxPro 9, SP2. I have a function that simply adds desired text to a log file with a date and time stamp precedding the text. Before adding, it checks to see if that particular string of text already exist. If it does, it replaces the date and time stamp with the current date and time. If it does not, it adds to the end of the file. From the command line, I get the results expected. I have SRVANY running on a Windows 2003 server. It calls an exe that has a timer that when fired, calls a second exe. This code is in the second exe. However, when run from the server, the log entries are always added to the end of the log file, not replaced as expected. Since it works perfectly from the command window, I am clueless where to start.
FUNCTION SetLog
PARAMETER TextToAdd
* add text to log file with date/time stamp if the text does not exist, if it does, replace that line
IF FILE('MyLog.txt')
FileContents=FILETOSTR('My
Log.txt')
NewFile=''
LineAdded=.F.
FOR MyCount=1 TO MEMLINES(FileContents)
TheLine=MLINE(FileContents
,MyCount)
TheText=SUBSTR(MLINE(FileC
ontents,My
Count),24)
IF UPPER(ALLT(TheText))==UPPE
R(ALLT(Tex
tToAdd))
NewLine=TRANSFORM(DATETIME
())+' '+ALLT(TextToAdd)
LineAdded=.T.
ELSE
NewLine=TheLine
ENDIF
NewFile=NewFile+IIF(EMPTY(
NewFile),'
',CHR(13)+
CHR(10))+N
ewLine
NEXT
IF !LineAdded
NewFile=NewFile+IIF(EMPTY(
NewFile),'
',CHR(13)+
CHR(10))+ ;
TRANSFORM(DATETIME())+' '+ALLT(TextToAdd)
ENDIF
ELSE
NewFile=TRANSFORM(DATETIME
())+' '+ALLT(TextToAdd)
ENDIF
SET SAFETY OFF
STRTOFILE(NewFile,'MyLog.t
xt')
SET SAFETY ON
Start Free Trial