Uncomment these lines in the code and it should start working:
$process.BeginOutputReadLine()
$process.BeginErrorReadLine()
Write-Error Write-Host , , : script
, :
Invoke-Executable ping "127.0.0.1"
, redir:
Invoke-Executable powershell 'import-module nonexistant -ea continue;exit'
:
function Invoke-Executable($ExePath, $ExeArgs)
{
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $ExePath
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = $ExeArgs
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $pinfo
$errEvent = Register-ObjectEvent -InputObj $process `
-Event "ErrorDataReceived" `
-Action `
{
param
(
[System.Object] $sender,
[System.Diagnostics.DataReceivedEventArgs] $e
)
Write-host $e.Data
}
$outEvent = Register-ObjectEvent -InputObj $process `
-Event "OutputDataReceived" `
-Action `
{
param
(
[System.Object] $sender,
[System.Diagnostics.DataReceivedEventArgs] $e
)
Write-Host $e.Data
}
[Void] $process.Start()
$process.BeginOutputReadLine()
$process.BeginErrorReadLine()
while (!$process.HasExited)
{
Start-Sleep -Milliseconds 250
Write-Host "ping"
}
}