如何在Inno Setup中使用空格处理路径?

问题描述:

在使用Inno Setup安装程序时,我想允许路径带有空格(例如,程序文件).但是带有空格的路径会使我的已安装服务崩溃.

I want to allow paths with spaces (for example program files) when installing my program with Inno Setup. However paths with spaces let my installed service crash.

Inno Setup文件如下:

The Inno Setup file looks like this:

[Setup]
AppName=Demo
DefaultDirName={pf}\demo

[Files]
Source: "bin\nssm.exe"; DestDir: "{app}"
Source: "bin\jdk1.8.0_152\jre\*"; DestDir: "{app}\jre"; Flags: recursesubdirs
Source: "build\libs\demo.jar"; DestDir: "{app}"

[Run]
Filename: "{app}\nssm.exe"; \
    Parameters: "install demo ""{app}\jre\bin\java.exe"" -jar ""{app}\demo.jar"""
Filename: "{app}\nssm.exe"; Parameters: "start demo"

"nssm.exe";是将Java应用程序作为Windows服务执行的服务包装器.

"nssm.exe" is a service wrapper to execute a java application as a windows service.

关键部分是这一行:

Filename: "{app}\nssm.exe"; \
     Parameters: "install demo ""{app}\jre\bin\java.exe"" -jar ""{app}\demo.jar"""

根据此问题/答案中的建议,我试图使用双双引号,但这无济于事,该服务仍在崩溃.如果我将 DefaultDirName 更改为没有空格的路径,那么一切都会按预期进行.

As suggested in this question/answer, I tried to use double double quotes, but this doesn't help, the service is still crashing. If I change DefaultDirName to a path without spaces everything works as expected.

DefaultDirName=c:\demo

我该如何处理带空格的路径?

How do I have to handle paths with spaces?

问题是Inno Setup和nssm的组合,它们都在转义双引号和双引号.这使得必须使用多个双引号.

The problem was the combination of Inno Setup and nssm, which both are escaping double quotes with double quotes. That makes multiple double quotes necessary.

解决方案:

Filename: "{app}\nssm.exe"; Parameters: "install demo ""{app}\jre\bin\java.exe"" -jar """"""{app}\demo.jar"""""""

请参见 nssm文档报价问题"部分.

See nssm documentation section "Quoting issues".