Hey guys, me again :p
I think the title says it all, Is there a way to read from a file while another program is using it?
I'm running a server and I want to create an application that reads the server log files and can execute commands on the server, but I can't open the log file when the server's running.
I know it's possible with php(and c++, java, ect...), but I'm not that great at it and I can't see any reason why it wouldn't work with dbpro.
I've tried it with both the inbuilt commands and Matrix1utils, both give 0 for file exist("server/log.txt") while the server is running, but work fine when it's not.
So, any ideas?
Here's the source, despite it probably being useless unless you have the server(Altitude game server) to test it:
Rem Project: Alti - coop teams
Rem Created: Thursday, June 28, 2012
Rem ***** Main Source File *****
global file_position
global changed
dim player_name$(15)
dim chars$(200)
Print "Loading log file..."
if file exist ("servers/log.txt") = 0
print "The log file could not be loaded."
print "Make sure this file is in the Alitude folder."
print ""
print "Press any key to exit."
wait key : end
ENDIF
file_length = find_file_length("servers/log.txt")
print "log length: "+str$(file_length)
print "Waiting for changes."
do
open datafile to read 1,"servers/log.txt"
set datafile position 1,file_position
a$ = datafile string$(1)
if datafile end(1) = 0
changed = 1
ENDIF
if changed = 1
print a$
repeat
s$ = datafile string$(1)
until datafile end(1) = 1
file_position = datafile position(1)
print file_position
check_text(a$)
changed = 0
ENDIF
close datafile 1
LOOP
function find_file_length(file_name$)
file_number = find free file()
open datafile to read file_number,file_name$
length = 0
repeat
inc length
a$ = datafile string$(1)
until datafile end(file_number) = 1
file_position = datafile position(file_number)
close datafile file_number
dec length
ENDFUNCTION length
function check_text(a$)
for n = 1 to len(a$)
chars$(n) = mid$(a$,n)
next n
print "player" + str$(get_val("player")) +": " + "nickname = "+chr$(34) + get_string("nickname",a$)+chr$(34)
ENDFUNCTION
function get_val(s$)
l = len(s$)
x = 0
repeat
inc x
m = 0
for n = 0 to l-1
if chars$(x+n) = mid$(s$,n+1) then inc m
NEXT
until m = l
inc x,l+2
if chars$(x+1) = ","
a$ = chars$(x)
ret = val(a$)
else
a$ = chars$(x) + chars$(x+1)
ret = val(a$)
ENDIF
ENDFUNCTION ret
function get_string(s$,a$)
l = len(s$)
x = 0
repeat
inc x
m = 0
for n = 0 to l-1
if chars$(x+n) = mid$(s$,n+1) then inc m
NEXT
until m = l
inc x,l+3
n = 0
repeat
inc n
if chars$(x+n) = chr$(34) then done = 1
until done = 1
ret$ = mid$(a$,x,n)
ENDFUNCTION ret$
PS. sorry if this is the wrong forum :/
The application's not exactly something "Newcomers" would write, and I'm not new myself, but the concept of loading a file being used by another program seemed pretty basic, so I posted here.