【问题标题】:Installing Java with silent install into a directory with spaces使用静默安装方式将 Java 安装到带空格的目录中
【发布时间】:2013-01-28 01:31:03
【问题描述】:

我正在尝试使用静默模式安装 Java,并指定包含空格的安装目录。当我这样做时,它会弹出“Windows Installer”对话框,指示其中一个参数不正确。如果我使用短路径名,它可以正常工作,但我真的不希望使用短目录名,因为这是存储在注册表中的值。

我要使用的命令...

jre-6u39-windows-i586.exe /s INSTALLDIR="C:\Program Files (x86)\Java"

这会弹出 Windows 安装程序对话框。

当我使用...

jre-6u39-windows-i586.exe /s INSTALLDIR=C:\Progra~2\Java

这行得通。

注意:“程序文件 (x86)”只是一个示例。这是安装在客户端站点并且他们选择安装目录,因此我们必须能够支持他们可能指定的任何目录。

知道如何进行静默安装但仍使用长路径名吗?

更新:

我想我会分享最终的解决方案。我发现我想分享的一件很酷的事情是,您可以禁止安装的自动重启,它会返回 3010 的退出代码。因此,您可以将重启推迟到另一个时间。下面是代码(重写了一些我们自己的抽象)

public bool InstallJava(string installPath, string logFile)
{
    bool rebootRequired = false;

    string fullLogFileName = Path.Combine(logFile, "JavaInstall.log");
    string arguments = string.Format("/s /v\"/qn REBOOT=Suppress INSTALLDIR=\\\"{0}\\\" STATIC=1 /L \\\"{1}\\\"\"", installPath, fullLogFileName);

    ProcessStartInfo startInfo = new ProcessStartInfo { RedirectStandardError = true, RedirectStandardOutput = true, RedirectStandardInput = true, UseShellExecute = false, CreateNoWindow = true, 
    FileName = "jre-7u25-windows-x64.exe",  Arguments = arguments };

    var process = Process.Start(startInfo);
    process.WaitForExit();

    if (process.ExitCode == 3010)
        rebootRequired = true;

    else if (process.ExitCode != 0)
    {
        // This just looks through the list of error codes and returns the appropriate message
        string expandedMessage = ExpandExitCode(StringResources.JAVA_INSTALL_ERROR, process.ExitCode, fullLogFileName);
        throw new Exception(expandedMessage);
    }

    return rebootRequired;
}

【问题讨论】:

  • 你试过 %ProgramFiles% 吗?
  • 我很抱歉不清楚。 “Program Files (x86)”只是一个例子。我已更改问题以正确反映这一点。

标签: java windows command-line cmd installation


【解决方案1】:

我记得以前遇到过这个问题......

如果将路径传递给安装程序,则需要使用引号 路径有空格。因为路径 arg 已经在引号中,所以您 需要用 '\' 转义每个引号,以便它通过。所以 该命令将是

       j2re.exe /s /v"/qn INSTALLDIR=\"C:\Program Files\JRE\""

参考:

http://docs.oracle.com/javase/1.5.0/docs/guide/deployment/deployment-guide/silent.html

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4966488

【讨论】:

  • 每隔一周我都会问自己,MS 的一位同事有什么愚蠢的想法将一个常用目录命名为“Program Files (x86)”。
  • @Ingo 与 cmd.exe 的“令人敬畏”的 shell 语法和统一的引号/参数处理相比,这几乎不是问题,事实上,整个子系统用于调用程序......除了,不是.
  • 我同意@pst:主要问题是 cmd.exe 的命令行处理基本上是脑死的。
  • @pst 正确。几十年来,MS 表明,他们对尝试从命令行使用其操作系统的人毫不在意。
猜你喜欢
  • 2013-02-23
  • 2013-03-01
  • 2015-01-03
  • 2011-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-10
  • 1970-01-01
相关资源
最近更新 更多