【问题标题】:You must provide a value expression following the '%' operator您必须在“%”运算符之后提供值表达式
【发布时间】:2015-07-06 15:57:16
【问题描述】:
PS C:\ImageMagick> convert -background transparent -fill hsb(0%,0%,0%) -font Arial -pointsize 18 -size 18x26 -gravity center label:p "output2.png"
At line:1 char:51
+ convert -background transparent -fill hsb(0%,0%,0%) -font Arial -pointsize 18 -s ...
+                                                   ~
You must provide a value expression following the '%' operator.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression

上面的命令在 cmd 窗口中没有任何问题,但在 PowerShell 中以红色文本出现错误,我已在上面粘贴了该错误。我看了很多文章,但还没有想出一个好的解决方案。

虽然他们可能在谈论对 hsb 的调用,但我用引号括起来:

PS C:\ImageMagick> convert -background transparent -fill "hsb(0%,0%,0%)" -font Arial -pointsize 18 -size 18x26 -gravity center label:p "output2.png"
Invalid Parameter - transparent

这只会导致不同的问题。我尝试在命令前加上 &,这是我以前不熟悉的技术,但似乎没有解决任何问题。

【问题讨论】:

  • 要解决您的问题,您可以简单地省略“%”符号:0% = 0; 100% = 255。"%" 是 powershell 中的模运算符。您还可以引用整行并“点源”它(即:.“convert ....”)。

标签: powershell imagemagick


【解决方案1】:

PowerShell 不使用当前目录作为查找命令的宫殿。所以convert被解析为C:\Windows\System32\convert.exe

Get-Command convert|ft CommandType,Name,Definition

# CommandType Name        Definition
# ----------- ----        ----------
# Application convert.exe C:\Windows\System32\convert.exe

如果您想从当前目录调用convert.exe,请使用.\convert 而不是convert

【讨论】:

  • 这不是 OP 遇到的第一个问题,但这将是他的第二个问题。 :-) 很好的收获。
【解决方案2】:

PowerShell 将括号解释为分组表达式,因此它认为里面的 % 是余数(模数)运算符。您可以使用停止解析运算符--% 让 PowerShell 以“哑”模式进行解析,例如:

convert.exe --% -background transparent -fill hsb(0%,0%,0%) -font Arial -pointsize 18 -size 18x26 -gravity center label:p "output2.png"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-18
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    相关资源
    最近更新 更多