mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 15:19:58 -05:00
Added missing tool function to start processes
This commit is contained in:
parent
d1e345e201
commit
85c8a8890a
1 changed files with 37 additions and 0 deletions
37
lib/core/tools/Start-IcingaProcess.psm1
Normal file
37
lib/core/tools/Start-IcingaProcess.psm1
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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;
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue