exe 的命令行参数

发布于 2024-10-07 01:52:13 字数 1206 浏览 0 评论 0原文

我对 Powershell 字符串有一个小问题。我正在使用一个名为 SymmetricDS 的 Java 程序,它接受 Windows 批处理文件的参数以实现某些管理功能。其中之一是打开节点注册,传递一个包含节点组和 ID 的字符串:

& .\bin\sym.bat -p symmetric.properties --open-registration 'store,01'

在批处理文件中,调用 java,我上面传递的属性如下所示:

java -Dthis -Dthat -Dfoo -Dbar %1 %2 %3 %4 %5 %6 %7 %8 %9

java 本身中的函数在此之后失败部分:

int index = argument.trim().indexOf(",");
if (index < 0) {
    throw new SymmetricException("LauncherMissingFilenameTriggerSQL", OPTION_OPEN_REGISTRATION);
}

index显然是-1。我不知道为什么找不到逗号字符。我只知道当我在 .cmd 或 .bat 文件中运行相同的内容时,它工作得很好:

.\bin\sym.bat -p symmetric.properties --open-registration "store,01"

我怀疑这与 Powershell 的字符串是 Unicode 有关,并且在从那里到批处理文件的过程中发生了一些不正确的事情,并且然后进入java。

有人知道如何在 Powershell 中直接调用它吗?

已解决zdan 的答案有效,就像欺骗 Powershell 一样,如下所示:

.\bin\sym.bat -p symmetric.properties --open-registration '"store,01"'

I have a slight problem with Powershell strings. There is a Java program I'm using called SymmetricDS which accepts arguments to a Windows batch file for certain administrative functions. One of these is to open registration for a node, passing a string containing the node's group and id:

& .\bin\sym.bat -p symmetric.properties --open-registration 'store,01'

In the batch file, java is called, with properties I passed above being passed in like so:

java -Dthis -Dthat -Dfoo -Dbar %1 %2 %3 %4 %5 %6 %7 %8 %9

The function in the java itself fails after this part:

int index = argument.trim().indexOf(",");
if (index < 0) {
    throw new SymmetricException("LauncherMissingFilenameTriggerSQL", OPTION_OPEN_REGISTRATION);
}

index apparently is -1. Why it is not finding the comma character, I don't know. I just know that when I run the same in a .cmd or .bat file, it works just fine:

.\bin\sym.bat -p symmetric.properties --open-registration "store,01"

I suspect it has something to do with Powershell's string being Unicode, and something improper happens in their journey from there into a batch file and then into java.

Anybody know how I can call this directly in Powershell?

Resolved: zdan's answer works, as does tricking Powershell a little bit like this:

.\bin\sym.bat -p symmetric.properties --open-registration '"store,01"'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

通知家属抬走 2024-10-14 01:52:13

这不是unicode问题。你被 powershell 的解析器绊倒了。当您调用调用运算符时,powershell 会解析其余参数,然后将它们传递给您正在调用的脚本。字符串“store,01”周围的单引号被有效地去除,并被解释为一个扩展为两个单独参数的列表。

只需直接运行 cmd.exe,同时小心地引用您的命令字符串:

 cmd.exe /c ' .\sym.bat -p symmetric.properties --open-registration "store,01" '

请注意,您必须将命令作为单个字符串传递给 cmd.exe,否则它将被 powershell 解析。

It's not a unicode issue. You stumbling against powershell's parser. When you invoke the call operator, powershell parses the rest of your arguments and then passes them to the script you are calling. The single quotes around the string 'store,01' effectively get stripped and gets interpreted a list that is expanded into two separate arguments.

Just run cmd.exe directly, while carefully quoting your command string:

 cmd.exe /c ' .\sym.bat -p symmetric.properties --open-registration "store,01" '

Note that you have to pass the command to cmd.exe as a single string, otherwise it will be parsed by powershell.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文