有人可以告诉我如何在以下情况下避免此错误吗?
$codegenDir = "Z:\Desktop\Song-Renamer"
$PowerShellRepresentation = dir -path $MyMusicFolder -recurse -include *.mp3,*.m4a,*.wma,*.flac,*.ape | select -ExpandProperty FullName | $codegenDir\codegen.exe -s 10 20 | Out-String | ConvertFrom-Json
让我完全困惑的是,如果简单地省略 $codegenDir (见下文),代码运行正常。我“认为”我理解首先放置表达式的概念(在管道中的其他项目之前。但我不确定如何重新排列/拆分此代码,因此有问题的表达式 Codegen.exe 外部命令行是第一项在管道中(并且仍然能够通过管道将数据传递给它)。
$PowerShellRepresentation = dir -path $MyMusicFolder -recurse -include *.mp3,*.m4a,*.wma,*.flac,*.ape | select -ExpandProperty FullName | .\codegen.exe -s 10 20 | Out-String | ConvertFrom-Json
理想情况下,最好使用尽可能少的代码来做到这一点。