Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated standard output, function call vs script

  • Loading branch information...
commit 69268bf5c5ddb9ea91e36078b24887077b39c2a1 1 parent cddbeda
@sushihangover authored
Showing with 10 additions and 10 deletions.
  1. +10 −10 Do-StartProcess.ps1
View
20 Do-StartProcess.ps1
@@ -4,9 +4,9 @@ Copyright 2012 Robert Nees
Licensed under the Apache License, Version 2.0 (the "License");
http://sushihangover.blogspot.com
.SYNOPSIS
-Start background process and return standard output
+Start a background process and return standard output
.DESCRIPTION
-This scripts provides a wrapper to System.Diagnostics.Process and Added stdout as the return 'object', it will be returned as
+This script/function provides a wrapper to System.Diagnostics.Process and Added stdout as the return 'object', it will be returned as
an array of strings
Priority Parameter Options:
@@ -26,10 +26,10 @@ http://sushihangover.blogspot.com
#>
function Do-StartProcess {
param(
- [parameter(mandatory=$true,position=1)][Alias("cmd")][string]$cliCmd,
- [parameter(mandatory=$false,position=2)][Alias("args")][string]$cmdArgs="",
- [parameter(mandatory=$false,position=3)][Alias("wait")][boolean]$waitForExit = $true,
- [parameter(mandatory=$false,position=4)][Alias("priority")]
+ [parameter(mandatory=$true,position=1)][Alias("Cmd")][string]$cliCmd,
+ [parameter(mandatory=$false,position=2)][Alias("Args")][string]$cmdArgs="",
+ [parameter(mandatory=$false,position=3)][Alias("NoWait")][switch]$noWaitForExit,
+ [parameter(mandatory=$false,position=4)][Alias("Priority")]
[string]$cmdPriority=[System.Diagnostics.ProcessPriorityClass]::Idle
)
$ProcessInfo = New-Object System.Diagnostics.ProcessStartInfo
@@ -40,14 +40,14 @@ function Do-StartProcess {
$ProcessInfo.RedirectStandardOutput = $true
$newProcess = [System.Diagnostics.Process]::Start($ProcessInfo)
$newProcess.PriorityClass = $cmdPriority
- if ($waitForExit) {
- $newProcess.WaitForExit()
+ if (!$noWaitForExit.IsPresent) {
+# $newProcess.WaitForExit()
$stdOut = @()
+# $stdOut = $newProcess.StandardOutput.Read()
do {
$readLine = $newProcess.StandardOutput.ReadLine()
$stdOut += $readLine
} while ($readLine -ne $null)
-
}
- return $stdout
+ return $stdOut
}
Please sign in to comment.
Something went wrong with that request. Please try again.