0

I am unable to find the reason for the below script to fail in 1ES hosted pool:

Script:

$env:SSH_ROOT="C:\OpenSSH-Win64"

$pinfo=New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName="c:\\Program Files\\dotnet\\dotnet.exe"
#$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$dllDir="$(System.ArtifactsDirectory)".replace("\","\\")
$isMultipleDevice="$(isAndroidParallel)"
If($isMultipleDevice -eq "True"){
    $pinfo.Arguments = "$dllDir\\EmulatorAccess.dll """"startall"""" --api 29 --api 29"
}
else{
    $pinfo.Arguments = "$dllDir\\EmulatorAccess.dll """"start"""" """"28"""""
}
$p=New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
Write-Host "Setting path"
Set-Location -Path C:\Agent\_work\_temp
pwd
ls
Write-Host "-----------Displaying values in P----------"
Write-Host $p
Write-Host $p.value
$p.Start() | Out-Null
$p.WaitForExit(50000)
$stdout=$p.StandardOutput.ReadToEnd()
#$stderr=$p.StandardError.ReadLine()
Write-Host "stdout: $stdout"
If($isMultipleDevice -eq "True"){
    $stdOutArr = $stdout -split " "
    If($stdOutArr.Count -eq 5) {
    $arr=$stdout -split "`r`n"
  $stdoutOne=$arr[0]
  $stdoutTwo=$arr[1]
} else {
    $stdoutOne = $stdOutArr[0].trim() + " " + $stdOutArr[1].trim() + " " + $stdOutArr[2].trim()
    $stdoutTwo = $stdOutArr[3].trim() + " " + $stdOutArr[4].trim() + " " + $stdOutArr[5].trim()
}

Write-Host "stdout1: "
$stdoutOne
Write-Host "stdout2: "
$stdoutTwo
    $stdout=$stdoutOne+ "_" + $stdoutTwo
}
Write-Host "--------------------------------------------------------------"
Write-Host "##vso[task.setvariable variable=StopCode;]$stdout"

Error:

Exception calling “Start” with “0” argument(s): “The system cannot find the file specified” At D:\a_work_temp\de966ca7-f235-45de-844a-8ed9803020d4.ps1:31 char:1 $p.Start() | Out-Null

  • CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException

Note: The file “D:\a_work_temp\de966ca7-f235-45de-844a-8ed9803020d4.ps1” exist in the agent.

Vega
  • 25,886
  • 26
  • 85
  • 95
Mani
  • 1
  • 1
  • 2
    The implication is that `"c:\\Program Files\\dotnet\\dotnet.exe"` (which should be `"c:\Program Files\dotnet\dotnet.exe"`, but the extra `\ ` are benign) doesn't exist. Also: To synchronously execute console applications or batch files and capture their output, call them _directly_ (`c:\path\to\some.exe ...` or `& $exePath ...`), do _not_ use `Start-Process` (or the `System.Diagnostics.Process` API it is based on) - see [this answer](https://stackoverflow.com/a/51334633/45375). – mklement0 Aug 13 '21 at 19:36

0 Answers0