Quantcast
Viewing all articles
Browse latest Browse all 9764

Powershell in bat file closing console

I have a bat file that normalizes several folder audios.

I need to delete some lines from a txt file that will be used to eliminate custom tags in audio files.

I use the command below to run powershell via bat file:\

"%systemroot%\system32\windowspowershell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -Command "gci *.txt | foreach { (cat $_.fullname | ? { $_ -match 'METADATA|title|encoder' }) | set-content $_.fullname  }"

I use the -WindowStyle Hidden option so that the powershell console does not appear, but when the powershell command is executed, the bat console screen closes and it is terminated.

Code:

md "C:\Users\%username%\Desktop\Temp_normalizing_lufs"    ------> temp folder audio files being normalized   pushd "%Userprofile%\Desktop\µudios LUFS"                 ------> folder with the original audio files                                                                                                      __FOR /F "delims=" %%a in ('where .:*.mp3 ^|findstr /vi "_LOUDNORM  _EBU"') DO (                          |                  SET "filename=%%~na"                                                                                  |  ffmpeg -hide_banner -i "%%a" -af "[0:a]loudnorm=print_format=summary" -f null NUL 2> "%%~na.log"      |     @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input Integrated" "%%~na.log"') DO (SET II=%%b)               |  @FOR /F "tokens=4" %%b IN ('FINDSTR /C:"Input True Peak" "%%~na.log"') DO (SET ITP=%%b)               |  set original audio files values    @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input LRA" "%%~na.log"') DO (SET ILRA=%%b)                    |  to use as parameters in loudnorm  @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input Threshold" "%%~na.log"') DO (SET IT=%%b)                |  @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Target Offset" "%%~na.log"') DO (SET TO=%%b)                  |  DEL "%%~na.log"                                                                                     __|  SETLOCAL ENABLEDELAYEDEXPANSION  FOR /F "tokens=1,2 delims=," %%b IN ('ffprobe -v 0 -select_streams a -show_entries "stream=bit_rate,sample_rate" -of "csv=p=0" "!filename!.mp3"')     ----> getting the sample rate and bitrate of the original audio file to use as parameters in loudnorm  DO (        ffmpeg -hide_banner -i "!filename!.mp3" -an -f ffmetadata -vsync vfr "!filename!.txt""%systemroot%\system32\windowspowershell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -Command "gci !filename!.txt | foreach { (cat $_.fullname | ? { $_ -match 'METADATA|title|encoder' }) | set-content $_.fullname }"      ffmpeg -hide_banner -i "!filename!.mp3" -c:a copy -map_metadata -1 -vsync vfr "!filename!_not_tags.mp3"      ffmpeg -hide_banner -i "!filename!_not_tags.mp3" -i "!filename!.txt" -codec copy -id3v2_version 3 -map_metadata 1 -id3v2_version 3 -vsync vfr "!filename!_with_tags.mp3"          ffmpeg -hide_banner -i "!filename!_with_tags.mp3" -af "loudnorm=linear=true:I=!_vLUF!:LRA=11:tp=!_vPEAK!:measured_I=!II!:measured_LRA=!ILRA!:measured_tp=!ITP!:measured_thresh=!IT!:offset=!TO!:print_format=summary" -c:v copy -id3v2_version 3 -metadata disc="" -metadata comment="" -metadata lyrics-eng="" -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -acodec mp3 -b:a %%c -ar:a %%b "C:\Users\%username%\Desktop\Normalizando_lufs\!filename!.mp3"      del /q "C:\Users\CMG\Desktop\µudios LUFS\!filename!.txt"      del /q "C:\Users\CMG\Desktop\µudios LUFS\!filename!_not_tags.mp3"      del /q "C:\Users\CMG\Desktop\µudios LUFS\!filename!_with_tags.mp3"     )  ENDLOCAL)xcopy "C:\Users\%username%\Desktop\Temp_normalizing_lufs\*.mp3" "C:\Users\%username%\Desktop\Normalized µudios Lufs\LOUDNORM\MP3\LUFS %-10.0%" /y /s /i   ----> copying the audio files from the temporary folder to the final folder                                                                __del /q "C:\Users\%username%\Desktop\Temp_normalizing_lufs\*.*"    |rmdir "C:\Users\%username%\Desktop\Temp_normalizing_lufs" /s /q   |  Removing the temporary folder from the desktop                                                                __|

How to run powershell without the powershell console screen appearing and keeping the bat file console screen?

Note:
The powershell command is inside a for loop that is executed inside SETLOCAL ENABLEDELAYEDEXPANSION


Viewing all articles
Browse latest Browse all 9764

Trending Articles