Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在Powershell ISE中运行时,正在工作的Powershell命令报告异常_Node.js_Json_Powershell_Npm_Escaping - Fatal编程技术网

Node.js 在Powershell ISE中运行时,正在工作的Powershell命令报告异常

Node.js 在Powershell ISE中运行时,正在工作的Powershell命令报告异常,node.js,json,powershell,npm,escaping,Node.js,Json,Powershell,Npm,Escaping,我正在尝试编写一个powershell脚本,它使用Squoosh CLI批量调整图像大小 因为安装需要npm,所以我在windows上安装了npm,并安装了Squoosh CLI 可以从其web UI生成Squoosh CLI命令,因此我从那里获得了Squoosh命令: npx @squoosh/cli --resize '{"enabled":true,"width":2017,"height":1350,"method&q

我正在尝试编写一个powershell脚本,它使用Squoosh CLI批量调整图像大小

因为安装需要npm,所以我在windows上安装了npm,并安装了Squoosh CLI

可以从其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\","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}' $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,"height":1200,"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}' $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中?另一个类似的建议是控制台没有启用严格模式,所以我运行了
    setstrictmode-versionlatest
    并重新运行了命令,但仍然没有看到异常
  • 原因是什么?如何解决