问题描述
我使用PowerShell串一个小问题。有一个Java程序,我使用的是被称为它接受的参数为某些行政Windows批处理文件功能。其中之一是,以打开注册为一个节点,使含有该节点的组和id的字符串:
&安培; \\ BIN \\ sym.bat -p symmetric.properties --open登记店,01'
在批处理文件,JAVA调用,具有属性我上面传递在像这样通过:
的java -Dthis -Dthat -Dfoo -Dbar%1%2%3%4%5%6%7%8%9
在Java本身的功能,这部分失败后:
INT指数= argument.trim()的indexOf();
如果(指数℃下){
抛出新SymmetricException(LauncherMissingFilenameTriggerSQL,OPTION_OPEN_REGISTRATION);
}
首页
显然是-1。为什么它没有找到逗号,我不知道。我只知道,当我运行一个.cmd或.bat文件一样,它工作得很好:
\\ BIN \\ sym.bat -p symmetric.properties --open登记店,01。
我怀疑它是与Powershell的字符为统一code和不当的东西在他们的旅程发生了从那里进入一个批处理文件,然后到Java。
任何人都知道我可以直接在PowerShell中调用此?
解决:zdan's答案,工作方式确实诱骗PowerShell的有点像这样:
\\ BIN \\ sym.bat -p symmetric.properties --open登记'店,01'。
这不是一个单向code问题。您对绊脚石PowerShell中的解析器。当调用电话运营商,PowerShell的解析你的剩余参数,然后将它们传递给您呼叫的脚本。串绕的单引号'店,01'有效地获得剥夺,并得到除preTED被扩大成两个独立的参数列表。
就直接运行cmd.exe的,同时认真引用您的命令字符串:
的cmd.exe / c'的。\\ sym.bat -p symmetric.properties --open登记店,01'
请注意,你必须命令传递给CMD.EXE作为一个单一的字符串,否则它将被PowerShell的解析。
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"'
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.
这篇关于命令行参数到一个exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!