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

  • Hello Adam,

    This is a good proposal, but going with this solution means each release we need to update it, what about a hot fix? I think it might happen the same. I think this sharing is good and I encourage you to continue finding solutions like this and sharing. There is always learning for all of us.

    I will share you my thoughts on this.

    The reason for this to happen is that the OS/logger has a buffer after certain size it flushes the file, so at the end it does it but maybe not when you need it or the way you want it. Here I have few options I have used.

    Option 1) there are implementations of the Unix commands for windows. On which you will have the tail command Linux like. (Cygwin, mobaxterm, to give some examples)

    Option 2) Have you tried the tail option from the PowerShell?
    * Get-Content filepath -Wait -Tail 30
    docs.microsoft.com/.../get-content

    Option 3) if you open the file in a program let’s say notepad++ it detects when the file changes and ask you to reload it. The problem with this approach is that the file could be really big. But I pick this approach when I need to read the file and understand the errors Or when the log have reached the section I wanted.

    Jose
  • Thanks, I tried this PowerShell command and it worked. I am not sure why it works, because the file size still does not appear to change, but as it does work, I agree it's a better solution than using a custom batch file.