Page 1 of 1

Open and parse Winboard.debug file while in use by Winboard

Posted: Sat May 06, 2017 1:39 pm
by Stan Arts
So this morning I tried to create a simple Winboard.debug file parser in my Nemeton GUI so one can watch Winboard games in progress on a 3D board.

Easy enough. When I feed it a finished debug file it parses the games in there to the last current position.

Problem: Winboard or Windows denies acces to the file while being used by Winboard so this idea doesn't work.

But since text editors like Notepad can open Winboard.debug while in use there must be some way around it. Anyone know how? (In FreePascal?)

Re: Open and parse Winboard.debug file while in use by Winbo

Posted: Sat May 06, 2017 2:00 pm
by hgm
Indeed there is something strange going on here. I also noticed that NotePad can open debug files while they are being written, but WordPad cannot. So it must have something to do with the program that tries to open the file. Perhaps Windows API has calls to open a file for exclusive use.

Note that the latest WinBoard has an undocumented feature, where an argument of the -debugfile option that starts with three slashes is not interpreted as the name of a file to write on, but as the name of an executable to launch and pipe the data to. This could conceivably be useful for what you want to do.

Re: Open and parse Winboard.debug file while in use by Winbo

Posted: Sun May 07, 2017 12:34 pm
by Stan Arts
Thanks. Seems I might have a solution now and that the problem was actually my program putting on some sort of a lock when attempting to open to read, which Windows denies.
So Google suggests opening files as a stream with no locks to get around this problem and in FreePascal that can be done with the file handling functions of the SysUtils unit. FileOpen with the fmShareDenyNone argument and reading individual bytes from the file through FileRead.
Takes a bit of getting used to, can't even tell when a line ends yet..but I'm getting a stream of characters from the debug file now while Winboard runs. Hiep hiep hoera.

Yeah your later solution of being able to fire up an external executable to send the debug info to seems excellent. As sort of a third engine which can watch over the games or analyse as they happen which seems like a useful feature now we often have cores to spare.

Re: Open and parse Winboard.debug file while in use by Winbo

Posted: Sun May 07, 2017 10:26 pm
by jwes
Stan Arts wrote:Thanks. Seems I might have a solution now and that the problem was actually my program putting on some sort of a lock when attempting to open to read, which Windows denies.
So Google suggests opening files as a stream with no locks to get around this problem and in FreePascal that can be done with the file handling functions of the SysUtils unit. FileOpen with the fmShareDenyNone argument and reading individual bytes from the file through FileRead.
Takes a bit of getting used to, can't even tell when a line ends yet..but I'm getting a stream of characters from the debug file now while Winboard runs. Hiep hiep hoera.

Yeah your later solution of being able to fire up an external executable to send the debug info to seems excellent. As sort of a third engine which can watch over the games or analyse as they happen which seems like a useful feature now we often have cores to spare.
I have a debug tool that does something similar. I use it to replay games to try to recreate bugs when just analyzing a position does not reproduce it.

Re: Open and parse Winboard.debug file while in use by Winbo

Posted: Sun May 07, 2017 10:48 pm
by hgm
Stan Arts wrote:Yeah your later solution of being able to fire up an external executable to send the debug info to seems excellent. As sort of a third engine which can watch over the games or analyse as they happen which seems like a useful feature now we often have cores to spare.
The intended application was live broadcasting of games. I made a broadcast engine that filters games and relevant PVs out of the debug stream, and uploads them to a website.

This is problematic when the internet connection somehow stalls, though: the pipe will fill up, and eventually cause WinBoard to stall too, when writing to it. So perhaps a file buffer, which can hold unlimited data, mught be better after all.