Last active
November 10, 2022 13:51
-
-
Save mcc85s/9c32506a5e6f4e09b08b1bf50f02e3c2 to your computer and use it in GitHub Desktop.
An idea to extend process execution/handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Path = "File path" | |
$Arguments = "Arguments" | |
If (![System.IO.File]::Exists($Process)) | |
{ | |
Throw "File does not exist" | |
} | |
$Name = Split-Path $Path -Leaf | |
$WorkingDirectory = Split-Path $Path -Parent | |
$Process = [System.Diagnostics.Process]::New() | |
$ProcessName = $ProcessPath | | |
$Process.StartInfo = [System.Diagnostics.ProcessStartInfo]::New($Name) | |
$Process.WorkingDirectory = $WorkingDirectory | |
$Process.StartInfo.RedirectStandardOutput = 1 | |
$Process.StartInfo.UseShellExecute = 0 | |
$Process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden | |
$Process.Start() | |
$Process.BeginOutputReadLine() | |
$Process.WaitForExit() | |
$exitCode = $Process.ExitCode | |
$Process.Dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment