Can you determine if FFmpeg executed correctly based on the return?

Viewed 83

I have written a script to mass-tag a large audio library. The tag info is stored in an Access database. I wrote a vba sub that invokes an FFmpeg command line.

newCmdStr = ffmpeg -i myFile.mp3 tag-info output.mp3

Shell ("cmd.exe /k " & newCmdStr)

Is there a way to determine if it runs correctly? I tried printing the return MsgBox(Shell(newCmdStr)), but it seems to return a random number, I can't tell what indicates if the command worked.

The most likely error would be a file not found error, but there could be some other things. If it ran, I would log the filepath of the new file, if it failed I would note that.

1 Answers

Shell invokes a command asynchronously, and can never get a return value. It returns the Process ID.

Furthermore, it would return the program ID of the program you're trying to run, which, in this case, is cmd.exe since that's first in your string.

Use WScript.Shell instead, which has .Run which can invoke commands synchronously, or .Exec which invokes asynchronously but allows getting return values.

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("ffmpeg -i myFile.mp3 tag-info output.mp3")

Do While oExec.Status = 0
     DoEvents
     'You probably want to sleep here to prevent high CPU usage
     'See https://stackoverflow.com/a/469358/7296893
Loop

Debug.Print oExec.ExitCode
Related