Sunday, June 4, 2017

How-To Tail (ColdFusion) Log Files in Windows Command Line via PowerShell and .bat Script

Setting up a new environment, I wanted to tail my coldfusion log files. Usually this is simple in the CFEclipse or CFBuilder log window. Unfortunately, that doesn't work in my new environment (beside the point). So I needed a different solution.... PowerShell to the rescue! It turns out it is super simple to tail files in PowerShell via a command like $ Get-Content coldfusion-out.log -wait. Awesome! But when I save this to a .ps1 file and double-click, it just opens my text editor. How can I double click like a good old .bat file?... well make a a .bat file named the exact same with contents like this:
PowerShell.exe -executionpolicy remotesigned -File %~dpn0.ps1

Now I can double-click my .bat and launch a regular old command window that tails my log file using PowerShell.

In the end, the files look like this:

And the .bat file double-click to command window looks like this:

Rinse and repeat with different log file names for any other log files you want to tail. Of course, this has nothing specifically to do with ColdFusion, but that's what I use it for :-)