From 67d6b707767a63fe698412216fd088947546efd1 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 13 Apr 2021 17:40:10 +0100 Subject: [PATCH] JAL-3830 Improved jalview.bat to find either pwsh.exe or powershell.exe, and give better messages to the user --- utils/getdown/bin/jalview.bat | 52 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/utils/getdown/bin/jalview.bat b/utils/getdown/bin/jalview.bat index 428019b..0eca4e4 100755 --- a/utils/getdown/bin/jalview.bat +++ b/utils/getdown/bin/jalview.bat @@ -1,4 +1,50 @@ @ECHO OFF -SET ThisScriptsDirectory=%~dp0 -SET PowerShellScriptPath=%ThisScriptsDirectory%jalview.ps1 -PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' %*"; + +REM This is the Jalview batch script wrapper to run the powershell script of the same name. +REM There is nothing specific to Jalview. + +REM ****************************************************************************** +REM If you need to set a full path to the PowerShell executable please do so here: +SET PWSHPATH= +REM ****************************************************************************** + +REM This is some DOS magic to substitute the extension in the full path of this batch script with .ps1 +SET SCRIPTPATH=%~dpn0.ps1 + +REM PowerShell script isn't where it should be! +IF NOT EXIST %SCRIPTPATH% ( + ECHO Could not find PowerShell script %SCRIPTPATH%. Is %~nx0 in the right folder? + EXIT /B 1 +) + +REM Look for either pwsh.exe or powershell.exe if not set in PWSHPATH above. +REM pwsh.exe is preferred as it is likely to be a newer version. +SET PWSH= +IF DEFINED PWSHPATH ( + SET PWSH=%PWSHPATH% +) +FOR %%X IN (pwsh.exe powershell.exe) DO ( + IF NOT DEFINED PWSH ( + IF NOT "%%~$PATH:X" == "" ( + REM Found a PowerShell executable in the PATH + SET PWSH=%%X + GOTO end_looking + ) + ) +) +:end_looking + +IF NOT DEFINED PWSH ( + REM No PowerShell executable found -- tell the user what to do. + ECHO No PowerShell found in %%PATH%%. If PowerShell is installed either + ECHO 1. add it to your PATH, or + ECHO 2. edit the PWSHPATH value at the top of this file: + ECHO "%~dpnx0" + ECHO. + ECHO %~n0 on the command line requires PowerShell. To install PowerShell see + ECHO https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell + EXIT /B 2 +) + +REM Run the PowerShell script +%PWSH% -NoProfile -ExecutionPolicy Bypass -Command "& '%SCRIPTPATH%' %*"; -- 1.7.10.2