The FileSystem.CreateTextReader method is a great helper when writing WinDbg extensions. Unfortunately, when I create such a reader in JavaScript, the opened file gets locked and even reopening with the same script fails. Example js script:
function initializeScript()
{
return [new host.apiVersionSupport(1, 7)]
}
function readFirstLine(path) {
const fileSystem = host.namespace.Debugger.Utility.FileSystem;
if (!fileSystem.FileExists(path)) {
throw new Error(`File not found: ${path}`);
}
const reader = fileSystem.CreateTextReader(path, "Utf8");
return reader.ReadLine();
}
And its execution:
0:000> dx @$scriptContents.readFirstLine("C:\\temp\\test.txt")
@$scriptContents.readFirstLine("C:\\temp\\test.txt") : test line sd
Length : 0xc
0:000> dx @$scriptContents.readFirstLine("C:\\temp\\test.txt")
Error: Unable to create file [at test-script (line 25 col 5)]
I suspect that JS GC might eventually free it, but it is not deterministic and problematic. Could you please then provide us with a Close (or other) method to free the file handle deterministically?
The FileSystem.CreateTextReader method is a great helper when writing WinDbg extensions. Unfortunately, when I create such a reader in JavaScript, the opened file gets locked and even reopening with the same script fails. Example js script:
And its execution:
I suspect that JS GC might eventually free it, but it is not deterministic and problematic. Could you please then provide us with a Close (or other) method to free the file handle deterministically?