Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Reading from a file being used by another program.

Author
Message
Lewis999
13
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 29th Jun 2012 21:52
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:



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.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 29th Jun 2012 21:59
If FILE EXIST returns zero, it's possible that the file does not, in fact exist () - I think it would return 1 even if something else had opened the file. If the server is using the standard .NET or whatever file streams, the file probably isn't actually created in Windows until the server closes it, which probably doesn't happen until you shut it down. Can you see the file and its contents in Explorer while the server is running?

Lewis999
13
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 29th Jun 2012 22:01 Edited at: 29th Jun 2012 22:01
That's what I thought at first, but I can open the file in notepad, and as I said people have done similar things in php(http://altitudegame.com/forums/showthread.php?t=2708)


edit: yes, I can see it in explorer ^.^
nonZero
12
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 30th Jun 2012 09:00
can you not write a batch script to copy and overwrite (continously if needed) the log file to a different location?

Lewis999
13
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 30th Jun 2012 12:12 Edited at: 30th Jun 2012 13:12
Ok, I'll give it a shot.
I don't think it'll be fast enough though, unless I reset the log files when reach a certain size(which I'll probably do anyway ).
It needs to be pretty much instantaneous, unless I can make it read all the new lines, then it wouldn't matter if there was a few hundred ms delay...
Oh yeah, I could just do that xD
Thanks, I'll try it now :p

edit:
Ok, so that's weird.
I can still open the file with notepad and view it in explorer, but both dbpro and the batch file say it doesn't exist.
I'm confused screen shot...

edit 2:
It doesn't work because there's a space in "program files (x86)"
I'll fix it now...

edit 3:
nope...
The file's too big to copy that quickly...
meh. I give up :p
The only way I could do this is if dbpro could read the file directly, but it can't :/
oh well, I'll just have to try to write it in c++

Thanks for the help anyway
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st Jul 2012 05:55
Quote: "File Mapping
Sharing data between multiple programs running on the same computer can often be difficult. The File Map commands provided in the expansion pack makes this process much simpler. When creating a file map a global, shared amount of memory will be set up in the Operating System. This can then be read and written to by a Dark Basic Professional application. Then either other Dark Basic Professional applications or applications written in other programming languages that natively support file mapping can access the shared memory."


Enhancements Expansion Pack

hope this points you in the right direction...

Lewis999
13
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 1st Jul 2012 12:20
Thanks
Yeah, that is useful :p
Now I just need to test whether or not the server supports file mapping
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st Jul 2012 13:34
I can create a sample exe if it helps

Lewis999
13
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 3rd Jul 2012 02:03
No, It's fine.
I've just stopped work on this anyway
The reason I was doing it was because one of my favorite server on the game has diapered, It was a co-op server and used a script to read the log files and store records of all the times, so I decided to try and get a similar system working.

But a temp server's been put back up now, so IMO theirs not much point continuing, I might continue with it some other time, but for now I want to focus on the other things.


Thanks for the help anyway, I really appreciate the amount of time you must spend on the forums helping other people
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Jul 2012 02:33
still worth learning

thank you too and no worries

always happy to help as are all the members on here I am certain

shame about the server... thats why I encourage internal assets >.<

Login to post a reply

Server time is: 2024-04-27 11:17:44
Your offset time is: 2024-04-27 11:17:44