I am writing a Windows shell script that works with lock files. For the sake of knowing if some file is locked, I am testing the Handle* utility from SysInternals that, according to its docs:
«Handle is a utility that displays information about open handles for any process in the system. You can use it to see the programs that have a file open»
so I try it by creating a simple .txt
file:
C:\Windows\system32>echo Foo >> Foo.txt
C:\Windows\system32>notepad Foo.txt
(notepad appears on screen with a new file named Foo
.
C:\Windows\system32>handle Foo
Handle v3.51
Copyright (C) 1997-2013 Mark Russinovich
Sysinternals - www.sysinternals.com
No matching handles found.
What is going on here? My file is supposed to be open, and notepad should have a handle on it, but this line:
handle -p notepad | grep "Foo"
yields no results.
How can I use handle to know if my Foo.txt
file is in use (locked)?
Maybe someone could give me some examples of the usage of handle.