如何解决在 Powershell ISE 中运行时,工作 Powershell 命令报告异常
我正在尝试编写一个使用 Squoosh CLI 批量调整图像大小的 powershell 脚本。
由于 Squoosh CLI 需要 npm 安装,所以我在 windows 上安装了 npm 并安装了 Squoosh CLI
squoosh.app 可以从它的 Web UI 生成 Squoosh CLI 命令,所以我从那里得到了我的 squoosh 命令:
npx @squoosh/cli --resize '{"enabled":true,"width":2017,"height":1350,"method":"lanczos3","fitMethod":"stretch","premultiply":true,"linearRGB":true}'
--mozjpeg '{"quality":75,"baseline":false,"arithmetic":false,"progressive":true,"optimize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trellis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_subsample":2,"separate_chroma_quality":false,"chroma_quality":75}'
我进行了一些更改,以便可以将其粘贴到 powershell 以调整图像大小:
$DirectoryName = "F:\TEMP\images"
$Fullname = "F:\TEMP\images\01.jpeg"
squoosh-cli -s _squoosh -d $DirectoryName --resize '{"enabled":true,"height":1200,"method":\"lanczos3\","fitMethod":\"stretch\",\"linearRGB\":true}' --mozjpeg '{"quality":75,"chroma_quality":75}' $Fullname
注意 json 参数值被转义,因为我注意到 powershell 在 "lanczos3",\"fitMethod\"
报告错误,因为 fitMethod
是一个字符串值,它被双引号包围,powershell 抱怨。所以我只是逃避了整个json。它可以在 powershell 中运行。
但是当我将相同的脚本复制到 powershell ISE 时,尽管图像已成功压缩,但它仍报告错误。
PS C:\Users\Administrator> $DirectoryName = "F:\TEMP\images"
$Fullname = "F:\TEMP\images\01.jpeg"
squoosh-cli -s _squoosh -d $DirectoryName --resize '{"enabled":true,"chroma_quality":75}' $Fullname
node.exe : 1/1 √ Squoosh results:
所在位置('position' in EN) C:\Users\Administrator\AppData\Roaming\npm\squoosh-cli.ps1:15 字符('character' in EN): 3
+ & "node$exe" "$basedir/node_modules/@squoosh/cli/build/index.js" $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (1/1 √ Squoosh results::String) [],RemoteException
+ FullyQualifiedErrorId : NativeCommandError
F:\TEMP\images\01.jpeg: 842.72KB
└ _squoosh.jpg → 92.33KB (11.0%)
- 为什么异常只在 ISE 中显示,而在 powershell 中不显示?另一个类似的 answer 表明控制台没有打开严格模式,所以我运行了
Set-StrictMode -Version latest
并重新运行了命令,但仍然没有看到异常 - 原因是什么以及如何解决?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。