0

Actually, I've found so many solutions to this question, but none works. The program I'd like to run in Powershell is Reaper - a Digital Audio Workstation, and I'm going to use its command line tool for batch-processing audio files within a PS script. The code related to Reaper is as below:

reaper -batchconvert $output_path\audio\Reaper_filelist.txt

I'm going to use the Start-Process with -wait parameter to allow my script to wait for it to end then go on to the next line of code which is a Rename-Item function.

ls $processed_audio_path | Rename-Item -NewName {$_.name.Replace("- ", "")}

If PS doesn't wait for the process to finish, then the next line would throw an error, something like "no such file was found in the directory".

The suggestions I've found are here, here, and here. But none of those work. The problem is that Reaper doesn't accept the argument to be added separately as:

$exe = "reaper"
$arguments = "-batchconvert $output_path\audio\Reaper_filelist.txt"
Start-Process -filepath $exe -argumentlist $arguments -wait

or:

Start-Process -filepath reaper -argumentlist "-batchconvert $output_path\audio\Reaper_filelist.txt" -Wait

or:

Start-Process -filepath reaper -argumentlist @("-batchconvert", "$output_path\audio\Reaper_filelist.txt") -Wait

It can only work without a problem as a whole block like the first code line above. So what can I do now?

4

2 回答 2

1

我找到了解决这个问题的方法。
我想我需要描述更多关于这个的背景。我总是在后台用我的 Windows 启动 Reaper,当脚本调用 Reaper 的 BatchConvert 函数时,它会启动另一个 Reaper 实例,所以在转换音频文件时我得到了 2 个实例。这 - Reaper 的实例 - 可能是限制以下代码的可靠条件。我从这里这里发现了一些有用的东西。

最后,我得到了这样的代码,它可以工作:

# 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-26T07:51:23.847 回答
0

正如一条评论所提到的,可能是该进程启动了另一个进程,导致 powershell 在脚本中移动。如果是这种情况,您可以有一个 while 语句来等待文件被创建。

while (!(Test-Path "$output_path\audio\Reaper_filelist.txt")) { Start-Sleep 10 }
于 2018-12-25T15:38:13.917 回答