I am writing a PowerShell script that has to invoke a legacy Perl Script and display the output of this long running Perl script in real time to PowerShell as I would normally view in a Windows command prompt or interactive Putty SSH session. My requirement is to write the output of the Perl script to a log file in real time and display the results to the PowerShell in real time.
My problem is that once the Perl script finishes running, all of the results are then returned to PowerShell or my log files.
Here is a simplified sample of my PowerShell code.
#Test.ps1
$env:Path = "C:\Dev\perl583\bin;" + $env:Path
$WORKING_PATH="C:\Dev\scripts"
perl $WORKING_PATH\LegacyScript.pl *>> C:\Dev\results\realtime_output.txt
exit $LASTEXITCODE
Here is a sample Perl Script that simulates a long running operation invoked by the PowerShell script:
#LegacyScript.pl
for( $a = 1; $a < 6; $a = $a + 1 ){
print "New value of a: $a\n";
sleep(10)
}