JAL-3830 Improved jalview.bat to find either pwsh.exe or powershell.exe, and give...
[jalview.git] / utils / getdown / bin / jalview.bat
1 @ECHO OFF
2
3 REM This is the Jalview batch script wrapper to run the powershell script of the same name.
4 REM There is nothing specific to Jalview.
5
6 REM ******************************************************************************
7 REM If you need to set a full path to the PowerShell executable please do so here:
8 SET PWSHPATH=
9 REM ******************************************************************************
10
11 REM This is some DOS magic to substitute the extension in the full path of this batch script with .ps1
12 SET SCRIPTPATH=%~dpn0.ps1
13
14 REM PowerShell script isn't where it should be!
15 IF NOT EXIST %SCRIPTPATH% (
16   ECHO Could not find PowerShell script %SCRIPTPATH%.  Is %~nx0 in the right folder?
17   EXIT /B 1
18 )
19
20 REM Look for either pwsh.exe or powershell.exe if not set in PWSHPATH above.
21 REM pwsh.exe is preferred as it is likely to be a newer version.
22 SET PWSH=
23 IF DEFINED PWSHPATH (
24   SET PWSH=%PWSHPATH%
25 )
26 FOR %%X IN (pwsh.exe powershell.exe) DO (
27   IF NOT DEFINED PWSH ( 
28     IF NOT "%%~$PATH:X" == "" (
29       REM Found a PowerShell executable in the PATH
30       SET PWSH=%%X
31       GOTO end_looking
32     )
33   )
34 )
35 :end_looking
36
37 IF NOT DEFINED PWSH (
38   REM No PowerShell executable found -- tell the user what to do.
39   ECHO No PowerShell found in %%PATH%%. If PowerShell is installed either
40   ECHO 1. add it to your PATH, or
41   ECHO 2. edit the PWSHPATH value at the top of this file:
42   ECHO    "%~dpnx0"
43   ECHO.
44   ECHO %~n0 on the command line requires PowerShell. To install PowerShell see
45   ECHO https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell
46   EXIT /B 2
47 )
48
49 REM Run the PowerShell script
50 %PWSH% -NoProfile -ExecutionPolicy Bypass -Command "& '%SCRIPTPATH%' %*";