将Write-Output转换为输入作为命令

时间:2018-01-27 20:27:41

标签: powershell

基本上,我使用不同的启动参数运行此应用程序。 我经常在应用程序的文件夹中打开PowerShell并写下这样的东西。

.\Name.exe -specific -launch -parameters

应用程序将开始运行,所以我试图简化这一点并获取从其cfg文件启动应用程序的语法。

我一直在尝试

function startfunction {
    cls
    echo "---------------------------------------------------------"
    echo ""
    echo "     Enter Config Name"
    echo ""
    echo "---------------------------------------------------------"
    $name = Read-Host -Prompt 'Enter Config';

    Get-Content -Path .\application\configs\$name.cfg |
        Write-Output -OutVariable launch;

    Start-Process $launch;
}

$name.cfg的内容:

.\Name.exe -specific -launch -parameters

结果/错误:

Enter Config: Name
.\Name.exe -specific -launch -parameters
Start-Process : Cannot convert 'System.Collections.ArrayList' to the type
'System.String' required by parameter 'FilePath'. Specified method is not
supported.
At C:\PSM0001.ps1:38 char:17
+   Start-Process $launch;
+                 ~~~~~~~
     + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
     + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.StartProcessCommand

0 个答案:

没有答案
相关问题