Tail alternative for windows?

I mostly run Node-red on Linux machines, but have recently tried to monitor a log file for VLC on Windows with the "Tail" node. However, it seems that "Tail" requires that I close the file in VLC first (seems to be a Windows limitation) but that would defeat the purpose as I would stop logging. Are there any commonly accepted solutions to this kind of scenario?

Have you tried PowerShell's equivalent command?

The equivalent of tail -f ./log.txt:

Get-Content ./log.txt –Wait -Tail 5

That also has an alias of cat.

Of course, you can also use WSL though I saw somewhere that at least at one point there was a bug in WSL's inotify handling that causes the issue you are seeing with a workaround of tail -f /mnt/c/path/to/file ---disable-inotify

Fantastic solution, thank you.

Which solution is "perfect"

  • Powershell?
  • Wsl tail?

Hey Steve, are you suggesting that some of my solutions aren't perfect?! :rofl:

If course not Julian. Just wondered which perfect solution the OP used (for future readers of course) :slight_smile:

I ended up using the Powershell method with cat alias and some slight altercations (the wait flag was removed), and of course double slashes because Windows.

more specifically I used:

if (!msg.filename) node.error("msg.filename was undefined.");
msg.lineCount = (msg.lineCount || "5");
return { payload:`cat ${msg.filename} -Tail ${msg.lineCount}`};

in a function node connected to a powershell node

Weirdly, the powershell node seems to return the msg as a string, so I also follow it with a simple function containing

return {payload: msg};

to make it easier to process the results

Here is an example flow for future readers:

[{"id":"e3f7d836a142b015","type":"tab","label":"Cat/Tail Windows","disabled":false,"info":"","env":[]},{"id":"147b72268de22d5d","type":"powershell","z":"e3f7d836a142b015","name":"","x":570,"y":200,"wires":[["472d4ddc609143a4"],["034fa32829c5b2ff"]]},{"id":"472d4ddc609143a4","type":"function","z":"e3f7d836a142b015","name":"format payload","func":"return {payload: msg};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740,"y":180,"wires":[["ec51640c32e20a14"]]},{"id":"1e9a0eedf05ce1d0","type":"function","z":"e3f7d836a142b015","name":"PS cat","func":"if (!msg.filename) node.error(\"msg.filename was undefined.\");\nmsg.lineCount = (msg.lineCount || \"5\");\nreturn { payload:`cat ${msg.filename} -Tail ${msg.lineCount}`};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":200,"wires":[["147b72268de22d5d"]]},{"id":"034fa32829c5b2ff","type":"debug","z":"e3f7d836a142b015","name":"stderror","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":720,"y":220,"wires":[]},{"id":"ec51640c32e20a14","type":"debug","z":"e3f7d836a142b015","name":"stdout","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":180,"wires":[]},{"id":"a2fa5a5e448c5b6d","type":"comment","z":"e3f7d836a142b015","name":"Expects msg.filename and msg.lineCount","info":"","x":240,"y":160,"wires":[]},{"id":"2c15ec79251fdc17","type":"string","z":"e3f7d836a142b015","name":"format filename","methods":[{"name":"replaceAll","params":[{"type":"str","value":"\\\\"},{"type":"str","value":"\\\\\\\\"}]},{"name":"prepend","params":[{"type":"str","value":"\""}]},{"name":"append","params":[{"type":"str","value":"\""}]}],"prop":"filename","propout":"filename","object":"msg","objectout":"msg","x":280,"y":200,"wires":[["1e9a0eedf05ce1d0"]]},{"id":"d7224f9a6ff9b997","type":"inject","z":"e3f7d836a142b015","name":"test","props":[{"p":"filename","v":"C:\\Users\\USERNAME\\AppData\\Roaming\\vlc\\LOG.txt","vt":"str"},{"p":"lineCount","v":"10","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":200,"wires":[["2c15ec79251fdc17"]]}]
1 Like

Really? That is really not good, and should be fixed by raising an issue against that node. I'm surprised it even works.

It appears that it's been fixed in github, however the npm package hasn't been updated in 4 years.

No "of course" about it, just use forward slashes, they work just as well :grinning:

1 Like

I can't believe I didn't try this until now. Thanks again.

Will this work in all cases?

Pretty much. Certainly PowerShell is fine with it. DOS command prompt can be a more of a mixed bag and old Windows executables can sometimes not cope but very few of those still work anyway.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.