1

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?

9
  • The bottommost line should work, assuming $output_path is populated, forming a correct path to file list as a result. Grab stdout and stderr of that process like here stackoverflow.com/questions/8761888/… and debug what data does reaper.exe receive in its command line. Also there's a chance that reaper.exe is not on the path so you need to provide full path to executable. Commented Dec 25, 2018 at 8:58
  • @Vesper The $output_path is ok, I assigned the path before. The reason I run Reaper without its path is that I've set it to my system's environment variable. I'm going to test the stdout and stderr with your suggestion, thanks. Commented Dec 25, 2018 at 9:06
  • @Vesper I've tried the code with filename and arguments being replaced by Reaper and its own parameters, the result however, is nothing. I got stdout: stderr: exit code: + 0 Commented Dec 25, 2018 at 9:23
  • Probably then profile the app with Procmon or similar tool, it seems to not provide debug logs in standard IO streams, maybe you'll discover that it's not lanched with correct parameter set, either with encoding or with "extra" spaces in path resulting in the path being split into several arguments. (BTW it's always nice to try eliminating spaces from any passed path when dealing with an unknown app, who knows which API it uses to get path. Same with non-ASCII characters in path) Commented Dec 25, 2018 at 9:33
  • Are you sure that Reaper doesn't start another process and then exits the first one? That could explain why PS doesn't wait for it. Commented Dec 25, 2018 at 14:59

4 Answers 4

1

I've found a solution to this problem.
I think I need to describe more context about this. I always have Reaper launched with my Windows in the background, when the script calls the BatchConvert function of Reaper, it will fire up another instance of Reaper, so I got 2 instances of it when converting audio files. This - the instances of Reaper - could be a reliable condition to restrict the following code. I found something useful from here and here.

Finally, I got my code like this and it works:

# 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("- ", "")}
Sign up to request clarification or add additional context in comments.

1 Comment

If it's a second reaper process, maybe you can find the commandline and run it directly: get-wmiobject win32_process | ? name -eq reaper.exe | select commandline
1

I verified that this will start Reaper, converting any files specified in the file .\list.txt from the current directory, and wait for it to exit

Start-Process 'C:\Program Files\REAPER (x64)\reaper.exe' -ArgumentList '-batchconvert .\list.txt' -Wait

And if you'd like to verify using a freely available sample file

Invoke-WebRequest `
  https://download.samplelib.com/wav/sample-15s.wav `
  -OutFile C:\Users\Public\Downloads\sample-15s.wav

(1..20) | foreach {# Specify the sample to be converted 20 times
  'C:\Users\Public\Downloads\sample-15s.wav' |
    Out-File C:\Users\Public\downloads\list.txt -Append utf8
}

Start-Process `
  'C:\Program Files\REAPER (x64)\reaper.exe' `
  -ArgumentList '-batchconvert c:\Users\Public\Downloads\list.txt' -Wait

Notice however, that my example had to specify that the list.txt file should be in utf8 format for reaper to be able to process it.

Comments

0

As the one comment mentions, it could be that the process starts another process, causing powershell to move along in the script. If that's the case, you could have a while statement to wait for the file to be created.

while (!(Test-Path "$output_path\audio\Reaper_filelist.txt")) { Start-Sleep 10 }

3 Comments

First, the file generated by Reaper is not the .txt, this is the filelist with parameters required by Reaper. It actually outputs a .wav file in another location. Second, the next statement is to change the file name generated by Reaper, there is a problem if you use a Test-Path command that the file would be there at the beginning of the process, the process, however, would take a while to finish.
Second, when the file is detected to exist, the Rename-Item command would change its name at once, this would lead the results either the file being processed by Reaper is damaged of it doesn' have the permission to change the file's name because it is opened by another process.
There could be another approach by finding a process with your main process as a parent one. These could be helpful stackoverflow.com/questions/4762982/… stackoverflow.com/questions/33911332/…
0

I had to make a script wait for 7zip to finish extracting/archieving. This worked for me:

start-process "$($homedir)\7za.exe" -argumentlist $argL

while((get-process -ea Ignore 7za)){}

The script is trapped between two decorative curly braces and resumes execution only after 7za is finished with its task.

Greetings Johann

2 Comments

Nice take 👍. And you could improve on your answer by using the -Wait switch of Start-Process. Then you wouldn't need the resource demanding while loop as in the original question (the switch is just put in the wrong place).
Thank you for this valuable hint, much appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.