I am trying to run powershell script from VB and I want to see the output of the script as it is running inside a console application. With my script (shown below) when I run from powershell it shows "Command Sleep Starting" and then waits for 5 seconds and then displays the other text.
However, when I run from VB.NET program, the execution waits for 5 seconds and dumps all the text output at once. It doesn't execute first Write-Output command and then wait and then output as it should.
Write-Output "Command Sleeping Starting"
Start-Sleep -Seconds 5
Write-Output "Command ran successfully"
Any idea on how to show real-time execution output when I run the script from VB .Net Program?
Just for more info below is the code I used.
Dim start As New ProcessStartInfo
Dim ScriptsFolder As String = GetKeyValue("ScriptsFolder")
Console.WriteLine(ScriptsFolder.ToString())
start.FileName = "powershell.exe"
start.Arguments = ScriptsFolder + "\" + ScriptFile
start.UseShellExecute = False
start.RedirectStandardOutput = True
start.RedirectStandardError = True
Dim myproc As New Process
myproc.StartInfo = start
myproc.Start()
Dim so As System.IO.StreamReader
Dim se As System.IO.StreamReader
se = myproc.StandardError
so = myproc.StandardOutput
myproc.WaitForExit()
Console.WriteLine(so.ReadToEnd)
Console.WriteLine(se.ReadToEnd)