Saved Bookmarks
| 1. |
Solve : stripping info from cmd prog output and adding to text file? |
|
Answer» Hi all, "M04296 - LET ME BE THE ONE - BLESSID UNION OF SOULS.mp3";-15.94;-15.93;-15.96 Does anyone know how i could code a batch file to do this? And if not, does anyone have any other suggestions for how i can achieve what i want? I guess some sort of regular expression on the output of the SoX program is what i'm looking for. Any help is appreciated cheers. NM [year+ old attachment deleted by admin]You already got a good start on it. I would use a Nested For Loop and put your SOX command inside that second for loop. Code: [Select]for %%A in (*.mp3) do ( FOR /F "Tokens=4,5,6 delims= " %%G in ( 'SOX "%%~A" -n stats ^|findstr /C:"RMS lev DB"') do ( echo %%A %%G %%H %%I >>myfile.txt ) )Thanks for getting back to me about this Squashman. There is one small problem though, the 3 values (tokens 4, 5 and 6) aren't getting found and passed on to the text file. The call to the SoX program goes ok and the results of it's analysis print onto the CMD screen but the values are either not getting found or not being passed on correctly. This line here doesn't get called at all it seems as the filename ( %%A ) isn't put into the text file either. Code: [Select]echo %%A %%G %%H %%I >>myfile.txt Any ideas on what the problem might be? Cheers NMThere are some console programs output that doesn't play nice with batch file output. There are even a few MS utilities that you can't use a FOR loop in a batch file to CAPTURE the output. I tried loading SOX on my computer and I can't seem to get it work. If you can help me get that installed and configured I could probably figure out the issue with the output from SOX. This is what I got when I tried to run the same command you were running on a single MP3 file. Code: [Select]C:\Desktop_from_first_computer\music>sox Slipknot-Before_I_Forget.mp3 -n stats sox FAIL util: Unable to load MAD decoder library (libmad). sox FAIL formats: can't open input file `Slipknot-Before_I_Forget.mp3':Hi, you just need to put the attached dll file into the same folder as SoX Thanks for your help. Cheers NM [year+ old attachment deleted by admin]Wow! I have no idea what SOX is doing but you can't capture any of its output. It won't let you parse the output in a FOR LOOP nor will it redirect its output to a LOG file. So my original code will not work nor will redirection to a text file like this: Code: [Select]SOX "Stone_Sour-3030-150.mp3" -n stats 1>Temp.logOk. Not to worry. Not your fault. I really appreciate you going to all that trouble for me anyway. Have yourself a "Thanked". I've got 22,000 files to process so i might just have to write a program to analyse them in Flash Cheers NMI think SOX sends its output to stderr and not stdout Hi Salmon Trout, Does that mean there might be a way to capture the data afterall? Cheers NMTry Googling for "redirect stderr to stdout cmd"I've managed to find the command to reroute the output but i'm not sure when to apply that in the current script i have. And you were right, if i use the following command... Code: [Select]SOX "M03671 - WHINEY WHINEY - WILLI ONE BLOOD.mp3" -n stats 2>Temp.log i get a log file with the information that would usually be shown in the CMD screen, like this... Code: [Select] Overall Left Right DC offset -0.000025 0.000000 -0.000025 Min level -1.000000 -1.000000 -1.000000 Max level 1.000000 1.000000 1.000000 Pk lev dB 0.00 0.00 0.00 RMS lev dB -16.78 -17.03 -16.54 RMS Pk dB -9.06 -9.72 -9.06 RMS Tr dB -1.#J -1.#J -1.#J Crest factor - 7.10 6.71 Flat factor 5.61 6.39 5.14 Pk count 48.5 35 62 Bit-depth 29/29 29/29 29/29 Num samples 10.5M Length s 237.949 Scale max 1.000000 Window s 0.050 so is there some way that i can redirect the info from stderr to stdout so that the tokens and findstring are carried out ok? Cheers NM p.s. i'm basically TRYING to find where i should put the redirect code Code: [Select]2>&1 or how i should rewrite this to make it workI'm almost there. I'm redirecting the output to a log file then trying to use the FINDSTR command to search through the log file for one specific line but it isn't working exactly as planned and i get every line output to my final file. Here is my code... Code: [Select]echo Filename;Total RMS;Left RMS;Right RMS >> RMS_Stats.txt FOR %%A IN (*.mp3) DO ( SOX "%%A" -n stats 2>Temp.log FOR /F "Tokens=4,5,6 delims= " %%G IN (Temp.log) DO ( FINDSTR /F:Temp.log /C:"RMS lev dB" echo %%A;%%G;%%H;%%I >> RMS_Stats.txt ) ) pause Any advice on what i'm doing wrong? Cheers NMSweet, i finally figured it out!!! Code: [Select]echo Filename;Total RMS;Left RMS;Right RMS >> RMS_Stats.txt FOR %%A IN (*.mp3) DO ( SOX "%%A" -n stats 2>Temp.log FOR /F "Tokens=4,5,6 delims= " %%G IN ('FINDSTR /C:"RMS lev dB" Temp.log') DO ( echo %%A;%%G;%%H;%%I >> RMS_Stats.txt ) ) pause Thanks for all of your help guys. Cheers NMI was thinking of redirecting stdout to stderr and not a file... like this... Code: [Select] 2>&1 This way you don't need to use a temp file Something like this... Code: [Select]for %%A in (*.mp3) do ( FOR /F "Tokens=4,5,6 delims= " %%G in ( 'SOX "%%~A" -n stats 2^>^&1 ^|findstr /c:"RMS lev DB"') do ( echo %%A %%G %%H %%I >>myfile.txt ) ) Quote from: Salmon Trout on February 14, 2012, 10:45:58 AM I was thinking of redirecting stdout to stderr and not a file... like this...Bingo! Thanks for chiming in! Got super busy at work this morning. |
|