# Tail alternative for windows?

**URL:** <https://discourse.nodered.org/t/tail-alternative-for-windows/58415>\
**Category:** General\
**Created:** [15 February 2022 19:55 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415 "2022-02-15T19:55:55Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [15 February 2022 19:55 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/1 "2022-02-15T19:55:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [15 February 2022 20:21 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/2 "2022-02-15T20:21:47Z")

</div>

Have you tried PowerShell's equivalent command?

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

```nohighlight
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`

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [15 February 2022 20:31 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/3 "2022-02-15T20:31:10Z")

</div>

Fantastic solution, thank you.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 February 2022 20:34 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/4 "2022-02-15T20:34:05Z")

</div>

Which solution is "perfect"

- Powershell?
- Wsl tail?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [15 February 2022 20:35 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/5 "2022-02-15T20:35:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 February 2022 20:38 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/6 "2022-02-15T20:38:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [15 February 2022 22:02 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/7 "2022-02-15T22:02:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [15 February 2022 22:13 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/8 "2022-02-15T22:13:21Z")

</div>

more specifically I used:

```auto
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

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [15 February 2022 22:23 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/9 "2022-02-15T22:23:53Z")

</div>

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

```auto
return {payload: msg};

```

to make it easier to process the results

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [15 February 2022 22:30 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/10 "2022-02-15T22:30:26Z")

</div>

Here is an example flow for future readers:

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 February 2022 22:45 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/11 "2022-02-15T22:45:53Z")

</div>

> [@HaroldPetersInskipp](#):
>
> Weirdly, the powershell node seems to return the msg as a string,

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

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [15 February 2022 23:08 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/12 "2022-02-15T23:08:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [15 February 2022 23:24 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/13 "2022-02-15T23:24:55Z")

</div>

> [@HaroldPetersInskipp](#):
>
> of course double slashes because Windows

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

---

<div class="post-metadata">

**Author:** ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)\
**Post date:** [15 February 2022 23:31 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/14 "2022-02-15T23:31:56Z")

</div>

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

Will this work in all cases?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [16 February 2022 00:15 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/15 "2022-02-16T00:15:22Z")

</div>

> [@HaroldPetersInskipp](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 March 2022 00:15 UTC](https://discourse.nodered.org/t/tail-alternative-for-windows/58415/16 "2022-03-02T00:15:52Z")

</div>

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