首页 > 解决方案 > 在批处理文件中使用 wget 下载 JDK 安装程序

问题描述

就像标题中所说的那样,我正在尝试使用以下命令在批处理文件中下载 jdk 安装程序:

wget --verbose --show-progress --referer="https://download.oracle.com" --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe"

我从批处理文件中得到这个错误:

--2021-01-05 15:12:30--  https://download.oracle.com/otn-pub/java/jdk/15.0.1B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe
Resolving download.oracle.com (download.oracle.com)... 23.212.156.99
Connecting to download.oracle.com (download.oracle.com)|23.212.156.99|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/15.0.1B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe [following]
--2021-01-05 15:12:30--  https://edelivery.oracle.com/otn-pub/java/jdk/15.0.1B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe
Resolving edelivery.oracle.com (edelivery.oracle.com)... 2a02:26f0:2b00:3b4::366, 2a02:26f0:2b00:390::366, 104.124.198.35
Connecting to edelivery.oracle.com (edelivery.oracle.com)|2a02:26f0:2b00:3b4::366|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://download.oracle.com/otn-pub/java/jdk/15.0.1B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe?AuthParam=1609856056_4a223d45cbb97da535473401552470f5 [following]
--2021-01-05 15:12:31--  https://download.oracle.com/otn-pub/java/jdk/15.0.1B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe?AuthParam=1609856056_4a223d45cbb97da535473401552470f5
Connecting to download.oracle.com (download.oracle.com)|23.212.156.99|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2021-01-05 15:12:32 ERROR 404: Not Found.

当我直接在 CLI 中使用此命令行(更改 wget.exe 文件所在的 CD)时,它会正确下载安装程序,如下所示:

--2021-01-05 15:19:43--  https://download.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe
Resolving download.oracle.com (download.oracle.com)... 23.212.156.99
Connecting to download.oracle.com (download.oracle.com)|23.212.156.99|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe [following]
--2021-01-05 15:19:43--  https://edelivery.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe
Resolving edelivery.oracle.com (edelivery.oracle.com)... 2a02:26f0:2b00:390::366, 2a02:26f0:2b00:3b4::366, 104.126.235.187
Connecting to edelivery.oracle.com (edelivery.oracle.com)|2a02:26f0:2b00:390::366|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://download.oracle.com/otn-pub/java/jdk/15.0.1+9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe?AuthParam=1609856489_c1f5f2310bf675762561de7d78160532 [following]
--2021-01-05 15:19:44--  https://download.oracle.com/otn-pub/java/jdk/15.0.1+9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe?AuthParam=1609856489_c1f5f2310bf675762561de7d78160532
Connecting to download.oracle.com (download.oracle.com)|23.212.156.99|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 167452312 (160M) [application/octet-stream]
Saving to: 'jdk-15.0.1_windows-x64_bin.exe'

我真的需要使用这个命令一个脚本。

如果有人知道批处理文件和 CLI 之间可能出了什么问题,我将非常感谢您的帮助。

标签: javaeclipsebatch-filecommand-line-interfacewget

解决方案


比较输出中的 URL。
CLI URL 包含一个百分比符号%2B作为 URL 编码字母的一部分。但是批处理脚本输出缺少这个百分号,因此导致了错误的 URL。

  • 命令行输出15.0.1%2B9
  • 批量输出15.0.1B9

由于批处理使用百分号%来标识变量,因此如果您想按字面意思使用它,则必须对其进行转义。

因此,请尝试在批处理脚本中使用两个百分号%%。这应该会导致%您的 URL 中出现(正确的)单曲。


推荐阅读