0
setlocal enabledelayedexpansion

for %%b in (*.wav) do (
  set duration=0
  for /f "tokens=3,5" %%a in ('ffprobe -i "%%b" -show_entries format^=duration -v quiet -of csv^=p^=0') do (
    echo 'asdf' >> test.txt
  )
)

For some reason the above code isn't running properly. When I remove the "/f" part it works, but with the "/f" part it isn't setting the duration variable, I tried doing an "echo 'asdf' >> test.txt" inside of that loop as well and it doesn't work either, nothing I put into the "do" clause for the loop with /f is working.

Any ideas? I tried removing the "for %%b in (*.wav) do (" loop and didn't make a difference either.

Here's the output of ffprobe if I just run it by itself.

C:\Users\deama\Desktop\Empire\voiceacting_samples\gothic2\xardas>ffprobe -i OUTR
O_XARDAS_14_10.WAV -show_entries format=duration -v quiet -of csv=p=0
4.129546

C:\Users\deama\Desktop\Empire\voiceacting_samples\gothic2\xardas>

The script with the for loop is located in the same directory called "pop.bat".

Dmytro Lysak
  • 397
  • 1
  • 4
  • 11
  • 1
    `=` is a separator. To handle it as a literal `=`, you have to escape it like `^=`. As you mentioned it, `>` is one of the other chars which have to be escaped (`... in ('echo 'asdf' ^>^> "test.txt"') do ...`) – Stephan Feb 08 '23 at 19:21
  • 1
    And you have [another problem, too](https://stackoverflow.com/questions/30282784/variables-are-not-behaving-as-expected/30284028#30284028) – Stephan Feb 08 '23 at 19:23
  • @Stephan , doesn't seem to work, here's what I tried: – Dmytro Lysak Feb 08 '23 at 20:54
  • setlocal enabledelayedexpansion for %%b in (*.wav) do ( set duration=0 for /f "tokens=3,5" %%a in ('ffprobe -i "%%b" -show_entries format^=duration -v quiet -of csv^=p^=0') do ( echo 'asdf' >> test.txt ) ) – Dmytro Lysak Feb 08 '23 at 20:54
  • a `for /f` loops ignore empty lines / no output. So when a simple `... do echo something` doesn't work, it's a strong hint that the `ffprobe` command doesn't generate anything on STDOUT, maybe even that there are no *.wav files in the active working folder. Running with `echo off` should give some valuable insight. – Stephan Feb 09 '23 at 07:55
  • When the output is `4.129546` - guess what the third and fifth token would be? – Stephan Feb 09 '23 at 08:18
  • Ah nice, thanks guys, got it to finally work. – Dmytro Lysak Feb 09 '23 at 08:27

1 Answers1

0

Looks like something was wrong with the tokens or something, the following works:

for %%G in (*.wav) do (
  for /F "delims=" %%H in ('ffprobe.exe -v error -show_entries format^=duration -of default^=noprint_wrappers^=1:nokey^=1 "%%G" 2^>^&1') do (
  echo %%H >> test.txt
  )
)
Dmytro Lysak
  • 397
  • 1
  • 4
  • 11