0

I'm using below commands to install Java on one of the Windows packer instance however, I am getting below error as;

Cannot index into a null array.
At line:1 char:94
+ ... content | %{[regex]::matches($_, '(?:<a title="Download Java software ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Commands:-

[Net.ServicePointManager]::SecurityProtocol = "tls12"

$URL = (Invoke-WebRequest -UseBasicParsing https://www.java.com/en/download/manual.jsp).Content | %{[regex]::matches($_, '(?:<a title="Download Java software for Windows .64-bit." href=")(.*)(?:">)').Groups[1].Value}

Invoke-WebRequest -UseBasicParsing -OutFile jre8.exe $URL

Start-Process .\jre8.exe '/s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0' -wait

Looks like Oracle has removed the title string contents from webpage which is causing the error. Is there an another way/command to install it using powershell?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Sagar Jadhav
  • 385
  • 1
  • 5
  • 15
  • Check the result you get from the web request. It says JavaScript need to be enabled, so this won't work. – marsze Oct 06 '20 at 09:51
  • @marsze, I am not getting that error which you are getting. Well, I have removed regex and used direct download link using `Invoke-WebRequest -UseBasicParsing https://javadl.oracle.com/webapps/download/AutoDL?BundleId=242990_a4634525489241b9a9e1aa73d9e118e6 -OutFile jre8.exe` which then downloads the jre8.exe. Further I have executed `Start-Process .\jre8.exe '/s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0' -wait` but nothing happens. – Sagar Jadhav Oct 06 '20 at 10:51
  • @LukasKörfer, yes I did refer that url and tried installing java using chocolatey. Setup was getting downloaded but it is failing at the installation with below error; `Installing JRE 8.0.2610.12 32-bit Installing JRE8... ERROR: Running ["C:\Windows\TEMP\chocolatey\jre8\8.0.2610.12\JRE8x86.exe" /s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0 ] was not successful. Exit code was '1'. See log for possible error messages. The install of jre8 was NOT successful. Error while running 'C:\ProgramData\chocolatey\lib\jre8\tools\chocolateyInstall.ps1'. See log for details.` – Sagar Jadhav Oct 06 '20 at 15:47
  • Initially, I was running `Invoke-WebRequest` from aws system manager console but then I ran it from rdp server using powershell and it worked. Java got successfully downloaded and installed. But this worked without using regex string which I was using earlier in problem statement. For regex, I need to do some more engineering. – Sagar Jadhav Oct 06 '20 at 15:53

0 Answers0