I am trying to convert a .bat file to python, almost everything is working fine, only the compression part is not working, I point out the flags and the path to the "rar.exe", but it's not working at all in the python version. What I need to correct to have the same behavior of the ".bat" version?
Thank you
batVersion.bat
@echo off
setlocal EnableDelayedExpansion
set "FolderBaseName=myFolder"
set "DropBoxFolder=D:\Tests3円.asc\MyDropBox"
set "BaseOutputFolder=D:\Tests3円.asc\TEMP"
for %%I in (*.png) do (
set "slaveName=%%~nI"
set "slaveName=!slaveName:~6!
set "OutputFolder=%BaseOutputFolder%_!slaveName!"
echo !slaveName!
md "!OutputFolder!" 2>nul
for %%J in (*.mp4*) do (
ffmpeg -i "%%~fJ" -i "%%~fI" -filter_complex overlay "!OutputFolder!\%%~nJ.mp4"
)
"C:\Program Files\WinRAR\rar.exe" a -cfg- -ep1 -inul -m5 "%DropBoxFolder%\%FolderBaseName%_!slaveName!" "!slaveName:~6!\*"
rd /S /Q "!OutputFolder!"
)
pause
pythonVersion.py
def processVideos():
FolderBaseName = "myFolder"
DropBoxFolder = "D:\\Tests\3円.asc\\MyDropBox"
BaseOutputFolder = "D:\\Tests\3円.asc\\TEMP"
for img in os.listdir("D:\\Tests\3円.asc"):
if img.endswith(".png"):
slaveName = img.split('.')[0]
OutputFolder = BaseOutputFolder+'_'+slaveName + '\\'
#create tmp folder
if not os.path.exists(OutputFolder): os.makedirs(OutputFolder)
for video in os.listdir("D:\\Tests\3円.asc"):
if video.endswith(".mp4"):
command = [ 'ffmpeg',
'-i', "D:\\Tests\3円.asc\\"+video,
'-i', "D:\\Tests\3円.asc\\"+img,
'-filter_complex', 'overlay',
OutputFolder+'\\'+str(video)]
pipe = subprocess.Popen(command, stdout = subprocess.PIPE) #, bufsize=10**8
commandRar = [ 'C:\\Program Files\\WinRAR\\rar.exe',
'a',
'-cfg-',
'-ep1',
'-inul',
'-m5',
DropBoxFolder+'\\'+FolderBaseName+'_'+slaveName]
# this doesnt work, and also I only want it to happen after the conversion above has finished
pipeRar = subprocess.Popen(commandRar, stdout = subprocess.PIPE)
processVideos()
TessellatingHeckler
29.3k4 gold badges55 silver badges96 bronze badges
asked Jun 22, 2015 at 19:55
user1765661
5951 gold badge7 silver badges22 bronze badges
3 Answers 3
You need to use the communicate method for the Popen objects you're creating.
blah = Popen(...)
blah.communicate()
This will also block until it is finished, after which you can start the 2nd command.
answered Jun 22, 2015 at 20:03
Ami Tavory
76.7k13 gold badges152 silver badges196 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
user1765661
That works, but I am not compressing the correct folder. i want to compress the "TEMP_FODLER" where the videos are beeing saved out.
Ami Tavory
Not that familiar with Winrar, but your popen there does not seem identical to the Python version, which is missing some stuff at the end.
import subprocess
blah = subprocess.Popen('aaa.bat', stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
blah.communicate()
answered Nov 22, 2021 at 17:43
James Chan
972 silver badges13 bronze badges
1 Comment
Jeremy Caney
This appears to be the same as the accepted answer from six years ago, just with a bit more context (such as some sample parameters for
Popen().REN *.log *.txt
MKDIR LOG
FINDSTR "TYPE:1=20000" *.txt > TYPE-1-20000
FINDSTR "TYPE:2=50000" *.txt > TYPE-2-50000
FINDSTR "TYPE:3=100000" *.txt > TYPE-3-100000
FINDSTR "TYPE:4=500000" *.txt > TYPE-4-500000
FINDSTR "OFFLINE" *.txt > OFFLINE
FINDSTR "RTRCT " *.txt > RTRCT
FINDSTR "RJCT" *.txt > RJCT
FINDSTR "DSPNS" *.txt > DSPNS
FINDSTR "WITHDRAWAL" *.txt > WITHDRAWAL
REN *.? *.txt
MOVE "TYPE-1-20000.TXT" LOG
MOVE "TYPE-2-50000.TXT" LOG
MOVE "TYPE-3-100000.TXT" LOG
MOVE "TYPE-4-500000.TXT" LOG
MOVE "OFFLINE.TXT" LOG
MOVE "RTRCT.TXT" LOG
MOVE "RJCT.TXT" LOG
MOVE "DSPNS.TXT" LOG
MOVE "WITHDRAWAL.TXT" LOG
Comments
lang-py