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?
$output_pathis 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.$output_pathis 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.filenameandargumentsbeing replaced by Reaper and its own parameters, the result however, is nothing. I gotstdout: stderr: exit code: + 0