java - 使用静默安装将 Java 安装到带空格的目录中

标签 java windows command-line cmd installation

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

我要使用的命令...

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

这会弹出 Windows Installer 对话框。

当我使用...

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

这有效。

注意:“Program Files (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;
}

最佳答案

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

You need to use quotes when passing paths to the installer if the paths have spaces. Because the path arg is already in quotes, you need to escape each quote with a '\' so it gets passed through. So the command would be

       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

关于java - 使用静默安装将 Java 安装到带空格的目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14837697/

相关文章:

java - spring boot和JPA配置简单仓库

windows - 使用 wix 本地化默认 msi 字符串

windows - 如何使用 NDIS 过滤器驱动程序发送任意数据包?

node.js - 如何从没有格式的FFmpeg获取标准输出?

java - 标签的编写方法(没有java的JSP标签库)

java - Tomcat 前面的 Apache 无法正常工作

javascript - gulp 任务处理可写文件

user-interface - Mercurial 是否有允许命令行执行的 GitX 等价物?

command-line - 使用一行 shell 命令多次运行程序

java - 零是 Android 中 ScheduledThreadPoolExecutor 的有效 corePoolSize 吗?