我正在尝试使用
Start-Process
在Powershell Core中,使用变量指定要启动的进程。我知道
dotnet
在我的路径中,所以这是有效的:
$DotnetRunCommandApp = 'run --project path/to/my/project.csproj'
Start-Process dotnet -ArgumentList $DotnetRunCommandApp
然而,当我试图移动时
.net
变成这样的变量:
$DotnetCommand = 'dotnet'
$DotnetRunCommandApp = 'run --project path/to/my/project.csproj'
Start-Process $DotnetCommand -ArgumentList $DotnetRunCommandApp
或者甚至使用绝对路径
.net
这样地:
$DotnetCommand = Resolve-Path ((Get-Command dotnet).Source | Out-String -NoNewline)
if (-not (Test-Path $DotnetCommand)) {
Write-Error "Can not find '$DotnetCommand'"
} else {
Write-Debug "Found $DotnetCommand" # Logs "DEBUG: Found C:\Program Files\dotnet\dotnet.exe"
}
$DotnetRunCommandApp = 'run --project path/to/my/project.csproj'
Start-Process $DotnetCommand -ArgumentList $DotnetRunCommandApp
我得到一个
InvalidOperationException
:
This command cannot be run due to the error: The system cannot find the file specified.
不知道为什么
启动流程
无法找到该文件,尽管它确实存在于我的PATH中,甚至当我为cmdlt提供完整路径时也是如此。
我的最终目标是能够指定对象中的参数,并将该对象传递给
启动流程
。这是在我的构建代理上运行的pwsh脚本的一部分,用于测试Web作业模板。虽然我希望本地的行为略有不同,但请查看开关
$Azure
在......下面
$StartProcessParams = @{
FilePath = $DotnetCommand
ArgumentList = $DotnetRunCommandApp
RedirectStandardError = (Resolve-Path $WebJobErrorLogFile)
RedirectStandardOutput = (Resolve-Path $WebJobLogFile)
PassThru = $true;
# Logging works best if we keep the process in the same "window" on Azure. Locally let the
# WebJob run in a new windows to make it really easy to kill the process in case of any errors
NoNewWindow = $Azure;
}
$WebJobProcess = Start-Process $StartProcessParams