Проблемы с параметром запуска Powershell

5804
JimmyP

Вероятно, общий вопрос, но:

Когда я бегу

Start-Process ".\packages\PS-Get.0.1.0.0\NuGet.exe" update -RedirectStandardOutput ".\packages\PS-Get.0.1.0.0\NuGet.exe.Update.log" -RedirectStandardError ".\packages\PS-Get.0.1.0.0\NuGet.exe.Update.log" -WindowStyle Hidden 

Я получаю ошибку

Start-Process : Parameter set cannot be resolved using the specified named parameters. At line:1 char:14 + Start-Process <<<< ".\packages\PS-Get.0.1.0.0\NuGet.exe" update -RedirectStandardOutput ".\packages\ PS-Get.0.1.0.0\NuGet.exe.Update.log" -RedirectStandardError ".\packages\PS-Get.0.1.0.0\NuGet.exe.Update.log" -WindowStyle Hidden + CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.StartProcessCommand 

Но все из:

Start-Process ".\packages\PS-Get.0.1.0.0\NuGet.exe" update -RedirectStandardOutput ".\packages\PS-Get.0.1.0.0\NuGet.exe.Update.log"  Start-Process ".\packages\PS-Get.0.1.0.0\NuGet.exe" update -RedirectStandardError ".\packages\PS-Get.0.1.0.0\NuGet.exe.Update.log"  Start-Process ".\packages\PS-Get.0.1.0.0\NuGet.exe" update -WindowStyle Hidden 

Работает нормально ... что мне не хватает ??

3

1 ответ на вопрос

5
Richard
Get-Command -syntax Start-Process 

gives two entries (manual wrapping added, and removing common parameters):

Start-Process [-FilePath] <String> [[-ArgumentList] <String[]>] [-Credential <PSCredential>] [-WorkingDirectory <String>] [-LoadUserProfile] [-NoNewWindow] [-PassThru] [-RedirectStandardError <String>] [-RedirectStandardInput <String>] [-RedirectStandardOutput <String>] [-Wait] [-UseNewEnvironment] Start-Process [-FilePath] <String> [[-ArgumentList] <String[]>] [-WorkingDirectory <String>] [-PassThru] [-Verb <String>] [-Wait] [-WindowStyle <ProcessWindowStyle>] 

In your working cases specifying either -RedirectStandardOutput or -WindowStyle uniquely identifies which parameter set to use.

In your non-working case you have both of these parameters, but there is no parameter set that has both, hence PSH can't select one.

Аааа, я вижу. Спасибо ... так нет способа запустить в скрытом окне и перенаправить вывод, а? JimmyP 12 лет назад 0
@JimmyP: Не с командлетом (непосредственное использование [System.Diagnostics.Process] даст больше контроля, но неясно, насколько легко перенаправить на этом уровне в PSH. Конечно, сочетание стандартного вывода и графического интерфейса довольно редко в Окна ... Richard 12 лет назад 0