I have a Windows CE 5.0 machine with smb shares for a file \hard disk2\logs\myfile.err
.
This file is created by a batch script that redirects the stderr of another exe to that file: myapp.exe 2> "\hard disk2\logs\myfile.err"
.
This works suprisingly well considering that I can not open myfile.err
with NotepadCE
on the Windows CE machine while myapp.exe
is running. If I try NotepadCE shows a sharing violation error.
This same file can be read at the same time by its smb share without any problems.
Is there a way to enable other programs on the Windows CE machine to read this file without stopping myapp.exe
?
Why is it possible to read it via smb, but impossible to read it in another way?
As a workaround I managed to copy the file to another location and then read it from there.
Why is it possible to read it via smb, but impossible to read it in another way?
I would imagine this has to do with the options passed to CreateFile
.
For instance, opening a file with
CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, ...)
requests read access whilst allowing others to both read and write. This is likely what the SMB service does.
Whereas opening as
CreateFile(path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, ...)
requests read/write access while preventing others from writing. The batch script probably does this.
Finally NotepadCE might be trying to open the file using
CreateFile(path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, ...)
which will fail, as it is requesting write access which the batch interpreter has denied by passing only FILE_SHARE_READ
in the CreateFile
call.
Of course without access to the source code this is all guesswork, but if you are able to open the file locally as shown in the first example above then that supports the theory.
More about CreateFile in the Docs.
Is there a way to enable other programs on the Windows CE machine to read this file without stopping myapp.exe?
Sort of, yes. Rather than redirecting stderr just have myapp.exe write its output directly to myfile.err, passing FILE_SHARE_READ | FILE_SHARE_WRITE
in the CreateFile
call when creating the file. This would allow other programs that request write access to open myfile.err.