Skip to content

Commit

Permalink
improvement(core): tweak Invoke-ExternalCommand parameters (ScoopInst…
Browse files Browse the repository at this point in the history
…aller#3547)

- Redirect standard error to log file.
- Fix `-RunAs` error.
  - `-RunAs` and `-Log` cannot be used together.
  • Loading branch information
Hsiao-nan Cheung authored and Ash258 committed Aug 31, 2019
1 parent b7f0747 commit e5edd04
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ function run($exe, $arg, $msg, $continue_exit_codes) {
}

function Invoke-ExternalCommand {
[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName = "Default")]
[OutputType([Boolean])]
param (
[Parameter(Mandatory = $true,
Expand All @@ -386,6 +386,7 @@ function Invoke-ExternalCommand {
[Alias("Args")]
[String[]]
$ArgumentList,
[Parameter(ParameterSetName = "UseShellExecute")]
[Switch]
$RunAs,
[Alias("Msg")]
Expand All @@ -394,6 +395,7 @@ function Invoke-ExternalCommand {
[Alias("cec")]
[Hashtable]
$ContinueExitCodes,
[Parameter(ParameterSetName = "Default")]
[Alias("Log")]
[String]
$LogPath
Expand All @@ -410,9 +412,11 @@ function Invoke-ExternalCommand {
$Process.StartInfo.Arguments += " /lwe `"$LogPath`""
} else {
$Process.StartInfo.RedirectStandardOutput = $true
$Process.StartInfo.RedirectStandardError = $true
}
}
if ($RunAs) {
$Process.StartInfo.UseShellExecute = $true
$Process.StartInfo.Verb = 'RunAs'
}
try {
Expand Down

0 comments on commit e5edd04

Please sign in to comment.