thekid / inotify-win Goto Github PK
View Code? Open in Web Editor NEWA port of the inotify-wait tool for Windows
License: Other
A port of the inotify-wait tool for Windows
License: Other
Not entirely sure the cause, didn't dig at all, but figured I would share my issue.
bash-4.1$ make
/cygdrive/c/Windows/Microsoft.NET/Framework/v3.5/csc /nologo /target:exe /out:inotifywait.exe src\main\csharp_.cs
error CS2001: Source file 'srcmaincsharp_.cs' could not be found
fatal error CS2008: No inputs specified
make: *** [inotifywait.exe] Error 1
create , delete, move, there will be no problem, because I defined the cmd script, when the modification of the file will be executed twice script, which surprised me
Hi,
First of all: This seems like a great idea. If it does what it promises, it is great!
However, I have some requests:
Thanks!
When supplying NUL
as STDIN to inotifywait.exe
the program seems to crash without writing anything to STDERR or returning a non-zero exit code. This happens when running inotifywait.exe
as a windowless subprocess (my use case) or in a service, as well as using redirection in the shell, like so:
C:\path\to\inotify>inotifywait.exe . < NUL
C:\path\to\inotify>echo %ERRORLEVEL%
0
PS: Thanks for maintaining this! It has been very useful so far!
Edit: Perhaps this is intentional?
Hi:
I find the inotifywait.exe program very useful. However, I started to encounter problems when I started to use the "--exclude" option. By looking at Runner.cs, it looks to me that a "ReleaseMutex()" is missing. Here is (below) the change I made to the source code to solve my problem. This could be useful to others.
Thanks again,
TheGleM
From Runner.cs (original code):
if (null != _args.Exclude && _args.Exclude.IsMatch(e.Name))
{
continue;
}
From Runner.cs (modified code):
if (null != _args.Exclude && _args.Exclude.IsMatch(e.Name))
{
_mutex.ReleaseMutex();
continue;
}
We use inotifywait
in our little utility script gitwatch
, and with the help of a user -- and inotify-win
! -- we're now expanding our target platforms to Windows.
In this context I've run into the following two issues:
inotify-win
is formatted differently from the Linux variantinotify-win
uses a different part of the event-generating file's path to match against the exclusion regexp.I can provide analogous examples from both platforms to show the exact differences I've observed.
But first I wanted to ask if you are at all interested in improving the compatibility of this port. I think it would benefit users in general, because scripts building on top of inotifywait
will be more easily portable to Windows with inotify-win
, but there might be some cases where existing users of inotify-win
would have to change their scripts.
I'm no C# wizard but I'd also be willing to help with a PR to get this rolling if you think it's worthwile.
My setup is that I'm using Cygwin.
I have a samba share set up, and I'm using inotifywait.exe to monitor file changes in a directory. When I make the changes locally, they are noticed. But when the changes occur from the machine that the share lives on, they aren't.
Here's what I'm using:
inotifywait -r -m -e modify Y:/location/to/share | while read line ; do echo "Notified!" ; done &
Again, this works as expected when I modify files on my machine, but when they are logged to on the host, I'm not notified.
This could be a user error, too, As I'm also having issues watching specific files (it works with directories, but not individuals files), and using the cygwin-esque way of describing files (/cygdrive/y/location/to/share).
I've collected the output of both inotifywait
and inotify-win
for several test cases. The purpose of this is to show and compare the differences between the console output and the regexp behavior (these two are somewhat related) of the two variants.
Versions used when creating this comparison:
inotifywait
from inotify-tools
version 3.14-1ubuntu1 (Ubuntu 14.04 stable repo)inotify-win
current revision ( 6c0afa9 )Plain-text versions of this comparison can be found in this gist.
As both the files in the gist and the comments in this thread will be sequential, I have also created a plain-text side-by-side; it is included in the gist linked above, but best viewed in raw format.
Note: This is meant to be used as a resource/reference, so the comparison doesn't get buried in a thread with lots of discussion. I recommend using other issue/PR threads to discuss this, and only referencing this issue and the files in the gist. (@thekid, feel free to rename the issue if you have a better title :D)
The Linux version of inotifywait
supports multiple instances of the -e
option, to listen for multiple event types. This version only seems to look at the last option. For example:
$ inotifywait -e modify -e move -e create -e delete -e attrib -r .
===> Watching for 0 in C:\example -r for attrib
$ inotifywait -e modify -e move -e create -e delete -r .
===> Watching for Deleted in C:\example -r for delete
$ inotifywait -e modify -e move -e create -r .
===> Watching for Created in C:\example -r for create
$ inotifywait -e modify -e move -r .
===> Watching for Renamed in C:\example -r for move
Also the "Watching for" messages seem to repeat themselves somewhat, like "Watching for Created in C:\example -r for create".
Except for this odd message: "Watching for 0 in C:\example -r for attrib". I presume it is different because attrib
is not supported on Windows.
I have installed cwRsync on disk C which inclued cygwin.dll file. are there some connection with cygwin. do I need install cygwin then get inotifywait.exe. thanks for sharing
Add GitHub pipelines to do create .exe files and publish them for download under "Releases" as soon as a tag of the form v*.*.*
is pushed.
https://github.com/marketplace/actions/gh-release looks like a good fit, an alternative would be to simply use the gh
tool directly using YAML:
run: |
gh release create ${{ env.VERSION }} -n "${{ env.MESSAGE }}" -t "${{ env.NAME }}" ${{ env.FILES }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: "tag for release"
MESSAGE: "message for release"
NAME: "release name"
FILES: path/to/file1 path/to/file2 ...
When inotifywait is run un background the cygwin terminal hang
For exemple: inotifywait -m d: &
After it was impossible to use the terminal until inotifywait was killed
C:\temp>inotifywait.exe -m "C:\temp\1\"
Unhandled Exception: System.ArgumentException: Path does not exist: `C:\temp\1"`
at De.Thekid.INotify.ArgumentParser.ParseArgument(String option, String[] args, Int32& i, Arguments result)
at De.Thekid.INotify.ArgumentParser.Parse(String[] args)
at De.Thekid.INotify.Runner.Main(String[] args)
and that, of course, means that one cannot watch files with spaces in names. Also if the file being watched is a directory there is no trailing [back]slash after its name like in linux inotifywait, so once this bug is fixed it won't be possible to determine whether the space is part of the name or a separator.
inotifywait -e create,delete,modify,move -mrq C:\Test
When moving C:\Test\TestFolder1\testfile.txt to C:\Test\TestFolder2
It results in c:\Test DELETE TestFolder1\testfile.txt which is wrong,
should be
c:\Test MOVED_FROM TestFolder1\testfile.txt
c:\Test MOVED_TO TestFolder2\testfile.txt
Hi,
Is it possible to upload a compiled version to the repository?
It would be a great help and I don't have the environment required to compile it... :-(
Thanks in advance,
Mark
Hi, like inotify tools in linux cant we capture open event of a file from listening folder using this. if not ,is there any alternative to achieve this
While within a folder being watched inotifywait.exe C:\Sync
if I move/cut a file test.txt within folders of C:\Sync\folder1 say to C:\Sync\folder2
inotify will report
C:\Sync\ DELETE C:\Sync\folder1\test.txt
But not report the accompanying paste I expect :
C:\Sync\ CREATE C:\Sync\folder2\test.txt
It works perfectly well for files moved between of in/out of a Watched DIR but not inside one.
Windows 7 .net3.5 compiler
Any Ideas ?
Hello,
I just cloned it and make it. Result was inotifywait. After making i moved it to /bin/ (cygwin)
I tried several versions of execution - for any reason it is doing absolutely nothing.
Any ideas?
thank you,
regards
An easy way to reproduce this is with Visual Studio. When you save a file in Visual Studio, it actually creates a temporary file and then replaces the main file with the temporary file. There are several steps in that process. If you watch a directory and save a file with Visual Studio, only some of the steps will be reported and it will be inconsistent which will be reported. For example, here's what was reported the first time I saved a particular file:
CREATE C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home\1pufrzgv.y11~
And here's what was reported the second time:
CREATE C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home\0oo5h2cc.aff~
CREATE C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home\Home.cshtml~RF863f7e1.TMP
MODIFY,ISDIR C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home
I took a look at the code and this is caused by using code like this:
while (true)
{
var e = w.WaitForChanged(changes);
/// Process...
}
WaitForChanged
synchronously waits for changes in the directory of the type specified in changes
. If changes in the directory happen when processing a change notification, those changes are are not queued up anywhere and are lost.
The fix is to instead use the Created
, Changed
, Deleted
, and Renamed
events of the FileSystemWatcher
. The delegate specified will be called asynchrously when a change in the directory occurs.
I'll be sending a pull request shortly that makes this change. Saving that same file in Visual Studio with this code results in the following being reported, much more than got reported before:
CREATE C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home\ayjxpflb.rqc~
MODIFY,ISDIR C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home
MODIFY C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home\ayjxpflb.rqc~
CREATE C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home\Home.cshtmlRF864a436.TMPRF864a436.TMP
MODIFY,ISDIR C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home
DELETE C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home\Home.cshtml
MODIFY C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home\Home.cshtml
MODIFY,ISDIR C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home
MOVED_FROM C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home\ayjxpflb.rqc~
MOVED_TO C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home\Home.cshtml
MODIFY,ISDIR C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home
DELETE C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home\Home.cshtml~RF864a436.TMP
MODIFY,ISDIR C:\Users\Greg\Documents\Programming\animerecs-git\AnimeRecs.Web\Modules\Home
In Linux version since 3.20.1. Can be added to windows ver?
P.S.: And --includei too...
When creating a watcher
new FileSystemWatcher {
Path = path,
IncludeSubdirectories = _recursive,
Filter = "*.*"
})
the filter supposes there's a dot in file name, but there could be no dot.
Hi, very interesting - but what can it actually do? Can I trigger a script with this? How to use this, e.g. to monitor a directory and copy a file if changed inside it? Thanks!
I don't know if it is a featuer or a bug ๐ , but I have the following situation.
I run inotify-wait without the -m parameter and when i change a file, inotify-win captures the event successfully, but then, instead of exiting, it continues execution but fails to capture any more events.
Is this ok, or is something wrong?
Please add this package to Cygwin so when I look for Cygwin packages I can find and install.
inotifywait C:\
===> Watching C:\*.* for create, modify, delete, move
inotifywait "C:\"
Black screen, no output, hangs
inotifywait C:\Test
===> Watching C:\Test*.* for create, modify, delete, move
(works fine, cosmetic - no backslash delimiting path from wildcard)
inotifywait "C:\Test"
all OK like in 3)
inotifywait "C:\Test\"
like in 2) not working
inotifywait "C:\Test\."
all OK like in 3) and 4)
Results like 2) and 5) we can get if pass any not existing path. And even if we create this path later program still hangs.
Hi!
Just recently found your port and would love to try it under Windows! But I seem to be unable to get something working like
"inotifywait -m -e -create d:/examplefolder | windows_batch_to_do_something.cmd"
It is not about inotify not working correctly but more about how to use it in a concrete situation. I am unable to use Cygwin on the Windows machine, so I am stuck with win cmd...
Perhaps you already used it in such a way and have a small example :-) - if not, nevertheless, keep up the good work!
Regards
Holger
The command line argument "path" can't include spaces and ".
I shoud write
C:\progra~1
instead of
"C:\Program Files"
Hi,
I don't have the build environment for c or c#, I think many other people are the same, could you provide a binary download link? I would be nice if you can add the build requirements in the readme.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.