简体   繁体   English

在 Powershell 中运行可执行文件,特定文件名为 arguments

[英]Run executable in Powershell with specific filenames as arguments

I'm trying to batch-convert heic images to png images using Powershell.我正在尝试使用 Powershell 将 heic 图像批量转换为 png 图像。 What I have tried:我试过的:

Get-ChildItem -Include ('*.HEIC', '*.heic') -File | & .\bin\vips.exe copy $_.Name "$(_.BaseName).png"
Pause

and

Get-ChildItem -Include ('*.HEIC', '*.heic') -File | & .\bin\vips.exe copy $_.Name ($_.BaseName + '.png')
Pause

Both times I'm getting an error VipsForeignLoad: file ".png" does not exist which tells me it treats ".png" as the first (and only) argument and ignores the object Name and Basename properties.两次我都收到错误VipsForeignLoad: file ".png" does not exist这告诉我它将 ".png" 作为第一个(也是唯一的)参数并忽略 object Name 和 Basename 属性。

You're missing a $.你少了一个美元。 "$($_.BaseName).png" I would use -Filter vs -Include as it is more efficient. "$($_.BaseName).png" 我会使用 -Filter 与 -Include,因为它更有效。

Edited: Try this approach bypassing the Pipe and see if you get a different result.编辑:尝试绕过 Pipe 的这种方法,看看是否得到不同的结果。 I've also added some additional code to insure everything is fully evaluated.我还添加了一些额外的代码,以确保对所有内容进行全面评估。 If this approach works you can experiment with reducing come of the $() evaluation levels.如果这种方法有效,您可以尝试降低 $() 评估级别。

Also are you using Linux?您还在使用 Linux 吗? Some of my googling led me to believe you might be.我的一些谷歌搜索让我相信你可能是。 If so you should specify this in your tags for clarity.如果是这样,为了清楚起见,您应该在标签中指定这一点。

Clear-Host
$x = Get-ChildItem -Filter "*.HEIC" -File
ForEach ($File in $x) {
  & .\bin\vips.exe copy "$($File.FullName)" $("$($File.BaseName)" + ".pdf")
}

Also note the file extension in the Filter is case insensitive so no need to repeat.另请注意,过滤器中的文件扩展名不区分大小写,因此无需重复。

I'd also recommend adding the -Path parameter for clarity rather than assuming the default directory but that's just me.为了清楚起见,我还建议添加 -Path 参数,而不是假设默认目录,但这只是我。

HTH高温高压

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM