实际上,我已经找到了很多解决这个问题的方法,但是没有一个有效。我想在Powershell中运行的程序是Reaper -一个数字音频工作站,我将使用它的命令行工具在PS脚本中批量处理音频文件。收割机相关代码如下:
reaper -batchconvert $output_path\audio\Reaper_filelist.txt我将使用带有-wait参数的Start-Process来允许我的脚本等待它结束,然后继续下一行代码,这是一个Rename-Item函数。
ls $processed_audio_path | Rename-Item -NewName {$_.name.Replace("- ", "")}如果PS不等待进程完成,那么下一行将抛出一个错误,类似于“在目录中没有找到这样的文件”。
我找到的建议是here、here和here。但这些都不管用。问题是收割者不接受单独添加的参数为:
$exe = "reaper"
$arguments = "-batchconvert $output_path\audio\Reaper_filelist.txt"
Start-Process -filepath $exe -argumentlist $arguments -wait或者:
Start-Process -filepath reaper -argumentlist "-batchconvert $output_path\audio\Reaper_filelist.txt" -Wait或者:
Start-Process -filepath reaper -argumentlist @("-batchconvert", "$output_path\audio\Reaper_filelist.txt") -Wait它只能像上面的第一行代码一样作为一个整体没有问题地工作。那么我现在能做什么呢?
发布于 2018-12-26 15:51:24
我已经找到了解决这个问题的办法。
我想我需要描述更多关于这方面的背景。我总是在后台启动收割机,当脚本调用收割机的BatchConvert函数时,它会启动收割机的另一个实例,所以我在转换音频文件时得到了2个实例。这可能是限制以下代码的可靠条件。我在here和here上发现了一些有用的东西。
最后,我像这样得到了我的代码,它可以工作了:
# Batch converting through Reaper FX Chain
reaper -batchconvert $output_path\audio\Reaper_filelist.txt
while (@(Get-Process reaper).Count -eq 2){
Start-Sleep -Milliseconds 500
}
# Correct the Wrong file name produced by Reaper
ls $processed_audio_path | Rename-Item -NewName {$_.name.Replace("- ", "")}发布于 2018-12-25 23:38:14
正如其中一条评论所提到的,可能是该进程启动了另一个进程,导致powershell在脚本中移动。如果是这样的话,您可以使用while语句来等待文件创建。
while (!(Test-Path "$output_path\audio\Reaper_filelist.txt")) { Start-Sleep 10 }https://stackoverflow.com/questions/53920772
复制相似问题