gpt4 book ai didi

python - 将批处理命令转换为 python

转载 作者:行者123 更新时间:2023-12-05 05:25:27 24 4
gpt4 key购买 nike

我正在尝试将 .bat 文件转换为 python,几乎一切正常,只有压缩部分不起作用,我指出了标志和“rar.exe”的路径,但它不起作用全部在python版本中。我需要更正哪些内容才能具有与“.bat”版本相同的行为?

谢谢

batVersion.bat

@echo off

setlocal EnableDelayedExpansion
set "FolderBaseName=myFolder"

set "DropBoxFolder=D:\Tests\3.asc\MyDropBox"
set "BaseOutputFolder=D:\Tests\3.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

python版本.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()

最佳答案

您需要使用 communicate您正在创建的 Popen 对象的方法。

blah = Popen(...)
blah.communicate()

这也会阻塞直到它完成,之后你可以开始第二个命令。

关于python - 将批处理命令转换为 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30988671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com