0

我已经编写了一个基于 vbscript 的 .hta 安装程序来自动安装 PhoneGap/Cordova 以及所有先决条件(ant/jdk/bada sdk 等)。它几乎完成了,但我被困在需要直接下载 JDK 的部分。

如果您在命令提示符中复制粘贴此(长)行并且它可以工作

 wget --header "Cookie: gpw_e24=http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html;" ""http://download.oracle.com/otn-pub/java/jdk/7u17-b02/jdk-7u17-windows-i586.exe -O jdk.exe

它会直接下载JDK,绝对没问题。

当您将代码片段粘贴到记事本中并保存为 .vbs 并运行它时,它不起作用

Set objShell = CreateObject("WScript.Shell")
objShell.CurrentDirectory = "c:\"

'inQuotes function just puts quotes around the command parameters
objShell.Run inQuotes(WorkingDir & "\wget.exe") & " "  & " --header "  & inQuotes("Cookie: gpw_e24=http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html; ") & "http://download.oracle.com/otn-pub/java/jdk/7u17-b02/jdk-7u17-windows-i586.exe" & " -O" & " "  & inQuotes("jdk.exe"),1,True 


Function inQuotes(toQuote)
    'return with quotes around the toQuote parameter
    inQuotes = chr(34) & toQuote & chr(34)
End Function

在 objShell.Run 行的某个地方出现问题,wget 没有下载 jdk ...非常感谢任何帮助,谢谢:)

4

1 回答 1

1

您的变量WorkingDir是否已定义?如果我放一个回声:

strCmd = inQuotes(WorkingDir & "\wget.exe") & " " & " --header " _
& inQuotes("Cookie: gpw_e24=http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html; ") _
& "http://download.oracle.com/otn-pub/java/jdk/7u17-b02/jdk-7u17-windows-i586.exe" & " -O" & " "  & inQuotes("jdk.exe")
WScript.Echo strCmd

我明白了:

"\wget.exe"  --header "Cookie: gpw_e24=http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html; "http://download.oracle.com/otn-pub/java/jdk/7u17-b02/jdk-7u17-windows-i586.exe -O "jdk.exe"

这不会传递给原始命令。也许它会是这样的?

strCmd = "wget.exe --header " _
& inQuotes("Cookie: gpw_e24=http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html;") _
& " " & chr(34) &chr(34) & "http://download.oracle.com/otn-pub/java/jdk/7u17-b02/jdk-7u17-windows-i586.exe" _
& " -O jdk.exe"
WScript.Echo strCmd
于 2013-04-01T14:38:23.573 回答