windowsbatch-filecommand-promptmediainfo

MediaInfo (CLI) and Batch Files fail to work


I'm trying to learn how to use MediaInfo (CLI). In the process, I stumbled onto this thread that provided some promising value. MediaInfo CLI (Command Line Interface) Syntax Teaching Me Once & For All

However, when I try to script it in a batch file, MediaInfo will **NOT **process the mp4 file and read the data that I'm asking for.

If I Copy/**Paste **directly into the Command Prompt, it **WILL **return the values requested.

Has anyone else seen this before, or have any ideas what might be rendering the use of batch files with mediainfo useless?

Here's the code I'm running in both the batch file (FAILS) and directly in the Command Prompt (SUCCESS):

mediainfo --Output="General;File Name: %FileName%\r\nDuration: %Duration/String3%\r\nSize: %FileSize/String%" "D:\Movies\Saving Private Ryan (1998).mp4" >> D:\OutputTest.txt

My output when pasting/typing directly into Command Prompt:

File Name: Saving Private Ryan (1998)
Duration: 02:49:26.848
Size: 10.8 GiB

My output when running the exact same code in batch file:

File Name: 
Duration: 
Size: 

Thanks,

Software: W10Pro v22H2 (up to date) MediaInfo CLI x64 v23.07 (latest version)


EDIT:


Hi Compo,

To answer your question: No, I failed to escape those % characters in my batch script. I ran your example and the script ran without issue.

I corrected my script based on your suggestion from % to %%.

Final output for my test code is working:

mediainfo.exe --Output="General;File Name: %%FileName%%\r\nDuration: %%Duration/String3%%\r\nSize: %%FileSize/String%%" "D:\Movies\Saving Private Ryan (1998).mp4" >> "D:\OutputTest.txt"

Solution

  • This is not about MediaInfo, it is about Windows batch.

    If I Copy/**Paste **directly into the Command Prompt, it **WILL **return the values requested.

    Copy/paste is not a copy of the meaning of what you copy/paste, because Windows batch processor interprets some characters (here, the %), similar to the bold words you wrote with ** (bold is in bold but I actually wrote **bold**, there is an interpreter and copy/paste of **bold** would not be same in notepad as in this place).

    You need to escape % character, and the character for escaping is % so replace "%" by "%%" and it works (MediaInfo, or any other tool, will receive "%" because the interpreter interprets "%%" as "%" and provides "%" to the tool; when you write "%" the batch interpreter interpret the sequence, in your case it is invalid, so "%" is discarded and "" is provided to the tool, not "%").