mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 15:19:58 -05:00
38 lines
1.1 KiB
PowerShell
38 lines
1.1 KiB
PowerShell
|
|
function Start-IcingaProcess()
|
||
|
|
{
|
||
|
|
param(
|
||
|
|
[string]$Executable,
|
||
|
|
[string]$Arguments,
|
||
|
|
[switch]$FlushNewLines
|
||
|
|
);
|
||
|
|
|
||
|
|
$processData = New-Object System.Diagnostics.ProcessStartInfo;
|
||
|
|
$processData.FileName = $Executable;
|
||
|
|
$processData.RedirectStandardError = $true;
|
||
|
|
$processData.RedirectStandardOutput = $true;
|
||
|
|
$processData.UseShellExecute = $false;
|
||
|
|
$processData.Arguments = $Arguments;
|
||
|
|
|
||
|
|
$process = New-Object System.Diagnostics.Process;
|
||
|
|
$process.StartInfo = $processData;
|
||
|
|
$process.Start() | Out-Null;
|
||
|
|
|
||
|
|
$stdout = $process.StandardOutput.ReadToEnd();
|
||
|
|
$stderr = $process.StandardError.ReadToEnd();
|
||
|
|
$process.WaitForExit();
|
||
|
|
|
||
|
|
if ($flushNewLines) {
|
||
|
|
$stdout = $stdout.Replace("`n", '').Replace("`r", '');
|
||
|
|
$stderr = $stderr.Replace("`n", '').Replace("`r", '');
|
||
|
|
} else {
|
||
|
|
if ($stdout.Contains("`n")) {
|
||
|
|
$stdout = $stdout.Substring(0, $stdout.LastIndexOf("`n"));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return @{
|
||
|
|
'Message' = $stdout;
|
||
|
|
'Error' = $stderr;
|
||
|
|
'ExitCode' = $process.ExitCode;
|
||
|
|
};
|
||
|
|
}
|