start-appserver view output on Windows

This is not really a question, more just sharing my knowledge in case it helps others. The "start-appserver.bat" included with Appian 18.3 has a problem, it tells you to "monitor" the server output in the log file, but Windows does not really allow you to monitor content being written to a file while it's open (similar to UNIX tail) as far as I know. The whole content is written when the file is closed - even if you check the size of the log on the disk it will appear to be the same and then jump when the server is shut down.

Due to this I wrote my own modified version of "start-appserver.bat" which I will share here, basically it uses PowerShell to capture program output line by line and write it to a file and the screen.

@echo off

set currentDir=%cd%
cd %~dp0
call set-appian-home.bat
set tomcatLogFile=%AE_HOME%\logs\tomcat-stdOut.log
if not exist "%AE_HOME%\logs\tomcat" mkdir %AE_HOME%\logs\tomcat
powershell "Add-Content %tomcatLogFile% """""""
start cmd /c "title Tomcat & echo Starting Appian. Monitor progress in %tomcatLogFile% & PowerShell -ExecutionPolicy Unrestricted ".\catalina.bat run 2^>^&1 ^| ForEach-Object { Write-Host $_; $_} ^| Add-Content %tomcatLogFile%""
cd "%currentDir%"

Most of it is the same as the file included in Appian, I just added one line and modified one line. The added line just adds one new line to the log file, this is not strictly necessary but just provides a separation between run sessions in the log. The method would still work without that added line. (If you are wondering why there are so many quotes it's because Command Prompt escapes a quote as three quotes.)

The modified line is the important one as I'm using Powershell to redirect the output.

The only problem with this method is that it leaves a blank line between every logline for stderr loglines. I can't work out why that is. If anyone has any tips please let me know, otherwise feel free to be informed by my learnings!

  Discussion posts and replies are publicly visible