Skip to content

Commit e765919

Browse files
committed
Fix compatibility with Powershell 5.1
Powershell 5.1 does not suppress error handling when STDERR is redirected to STDOUT, and also does not allow Join-Path with null values. Issue: #394 Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent 302ebab commit e765919

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

server/basedir-includes/oieserver.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ function Test-IsValidJavaVersion([string] $JavaCmd) {
143143
# Execute 'java -version' and capture the output from stderr
144144
# Example output: openjdk version "17.0.2" 2022-07-19
145145
try {
146-
$versionOutput = & $JavaCmd -version 2>&1
146+
$versionOutput = & {
147+
$ErrorActionPreference = 'Continue';
148+
& $JavaCmd -version 2>&1 | Out-String;
149+
};
147150
}
148151
catch {
149152
return $false
@@ -242,7 +245,10 @@ if (-not $FinalJavaCmd -and -not [string]::IsNullOrWhiteSpace($script:VmOptionsJ
242245
}
243246

244247
# Check JAVA_HOME (no fail-fast).
245-
if (-not $FinalJavaCmd -and (Test-Path -Path $env:JAVA_HOME -PathType Container)) {
248+
if (-not $FinalJavaCmd `
249+
-and -not [string]::IsNullOrWhiteSpace($env:JAVA_HOME) `
250+
-and (Test-Path -Path $env:JAVA_HOME -PathType Container)
251+
) {
246252
$javaHomePath = Join-Path -Path (Join-Path -Path $env:JAVA_HOME -ChildPath "bin") -ChildPath "java"
247253
if (Test-IsValidJavaVersion -JavaCmd $javaHomePath) {
248254
Write-Host "Info: Found suitable java version specified by the JAVA_HOME environment variable" -ForegroundColor Green

0 commit comments

Comments
 (0)