1

Following the solution at Windows batch assign output of a program to a variable, I am using the following code:

FOR /F %%I IN ('"ffprobe -v error -select_streams a:0 -show_entries stream=channels -print_format csv=p=0 %1"') DO ECHO %%I

This breaks for arguments containing parentheses (e.g. a file name). For example, a file titled "Test File (2017.22.02) [1].aac" causes the following error: [1].aac""') was unexpected at this time.

Any ideas on how to fix this?

Community
  • 1
  • 1
Makaveli84
  • 453
  • 6
  • 16

1 Answers1

4
FOR /F "tokens=*" %%I IN (
   'ffprobe -v error -select_streams a:0 -show_entries stream^=channels -print_format csv^=p^=0 "%~1"'
) DO ECHO %%I

try like this. The problem is that the path to file is passed with quotes and your whole command is enclosed with quotes. With removed quotes you'll need to escape the equal sign.

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • Yup, the quotes were indeed my problem. Escaping the equal sign instead of enclosing the whole command with quotes did the trick. Any reason though for using `"%~1"` and not `%1` when I am certain that `%1` will be enclosed with quotes? – Makaveli84 Feb 22 '17 at 12:24
  • 2
    @Makaveli84 - the `~` dequotes the parameter (if there are quotes) and then they are put again in case there are spaces in the first parameter. It is for robustness. – npocmaka Feb 22 '17 at 12:26