给定一个函数:function log2 {param ([double]$x) [Math]::Log($x) / [Math]::Log(2) }
预期:log2 45/120应生成-1.41503749928
Cannot process argument transformation on parameter 'x'. Cannot convert value "45/120" to type "System.Double". Error: "Input string was not in a correct format." At line:1 char:6 + log2 45/120 + ~~~~~~ + CategoryInfo : InvalidData: (:) [log2], ParameterBindingArgumentTransformationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,log2:为什么会这样?
发布于 2017-12-20 10:18:34
Powershell不知道作为命令参数的45/100应该是求值表达式还是字符串,因此它选择一个字符串。它这样做是为了保留命令的参数。它试图将字符串转换为双精度型,但它不能,因为它不是数字字符串。
例如,我输入以下命令:
Get-Value 12/19/2017在将12/19/2017传递给Get-Value之前,Powershell应该如何处理它?最安全的答案是什么都不做。如果Get-Value想要转换它,那不是命令行解析器的工作。
是的,这些是明确的:
Get-Value (12/19/2017)
Get-Value "12/19/2017"这是另一个例子。假设我想要所有以4开头并以1结尾且扩展名为.000的文件
Get-ChildItem 4*1.000https://stackoverflow.com/questions/47896805
复制相似问题