Powershell:与报价解析不一致/奇怪的行为? [英] Powershell: inconsistent/strange behavior with quote parsing?
问题描述
全部!我正在尝试使用PowerShell编译程序,但是命令被奇怪地解析了. 此命令可在cmd.exe中正确执行:
all! I'm trying to compile a program using PowerShell, but the command is being parsed strangely. This command executes correctly in cmd.exe:
dmd -od"bin" -of"bin\convHull.exe" -I"src" "src\concSort.d" "src\fileParser.d" "src\main.d" "src\pointLogic.d" "src\quickHull.d" "src\stupidHull.d" -D -O -release
但是PowerShell会将其执行为:( 蓝色 ,海军,紫色文本在PowerShell ISE中显示)
But PowerShell executes it as: (blue, navy, purple texts as they appear in PowerShell ISE)
dmd -od"bin" -of"bin \ convHull .exe" -I"src""src \ concSort.d" src \ fileParser.d" src \ main.d" src \ pointLogic.d" src \ quickHull.d" src \ stupidHull.d"-D -O-发布
这会引发以下错误:
The string starting:
At line:1 char:147
+ dmd -od"bin" -of"bin\convHull.exe" -I"src" "src\concSort.d" "src\fileParser.d" "src\main.d"
"src\pointLogic.d" "src\quickHull.d" "src\stupidHull.d <<<< " -D -O -release
is missing the terminator: ".
At line:1 char:163
因此,这似乎是将句点解释为报价.这是奇特的.其他人在PowerShell中遇到此问题吗?
So it seems to be interpreting a period as a quote. This is peculiar. Has anyone else had this problem with PowerShell?
我尝试过的事情:
- 转义引号
- 确保所有引号都是直引号"而不是斜角
- 在引号前放置一个空格(可以正确解析,但是程序不理解参数.)
谢谢, 查尔斯.
推荐答案
我认为这应该可以解决问题(添加换行符只是为了清楚起见,并删除了多余的引号):
I believe this should do the trick (newlines added for clarity only, and removal of extra quotes):
dmd '-od"bin"' '-of"bin\convHull.exe"' '-I"src"'
src\concSort.d src\fileParser.d src\main.d src\pointLogic.d src\quickHull.d src\stupidHull.d
-D -O -release
请注意,在引号()作为参数本身的一部分传递的情况下,我用单引号(')将整个参数括起来.从下面的实验可以可以看到,只有 -of"..."
需要有关它的引号.
Note that in the case where a quote (") is to be passed as part of the argument itself, I surrounded the entire argument with single quotes ('). From the experimentation below it can be seen that only -of"..."
needs the quotes about it.
快乐的编码.
在这个确切的产品上找不到很好的参考,但是请注意以下分析:
I can't find a good reference on this exact production, however note the following parsings:
-x"w." -> error: " expected (last " is special)
-x"w."" -> -x"w and ."" (the . starts a new token and the " in that starts
a quote; however, the quotes are not removed)
'-x"w."' -> -x"w." (extra quote fine, neither special)
-x"w" -> -x"w" (no . and " not special)
-x"w"" -> -x"w"" (no . and " not special)
a".b" -> a.b (didn't start with `-`, quotes removed)
a".b -> error: " expected (" is special)
因此,它确实确实与.
和-
组合有关(并且可能不是排他的).从上面我相信,以-
开头的令牌不会在令牌中包含.
字符作为有效字符,因此,词法分析器终止所述令牌并启动新的令牌-容易证明有一个很好的EBNF参考资料,而我没有.
So it does indeed appear to have something to do with the .
and -
combination (and it might not be exclusive). From the above I believe that a token starting with -
does not include the .
character as a valid character in the token so the lexer terminates said token and starts a new token -- easily provable with a good EBNF reference, which I don't have.
我能找到的最好的是附录C:PowerShell语法:
ParameterToken规则用于匹配cmdlet参数,例如-foo或- boolProp :.请注意,此规则还将与--foobar匹配,因此该规则具有 要在--token规则之前进行检查.
The ParameterToken rule is used to match cmdlet parameters such as -foo or - boolProp: . Note that this rule will also match --foobar, so this rule has to be checked before the --token rule.
<ParameterToken> = -[:letter:]+[:]{0 |1}
但是,这充其量是不完整的,甚至不包含字母"的定义.
However, this is incomplete at best and does not even include a definition of "letter".
这篇关于Powershell:与报价解析不一致/奇怪的行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!