python执行cmd命令

2020-01-09 16:23:01 浏览数 (1)

最典型的模块

一,执行cmd并读取返回值

代码语言:javascript复制
import subprocess

p = subprocess.Popen("ls",
        stdout=subprocess.PIPE, universal_newlines=True)
p.wait()
result_lines = p.stdout.readlines()

for line in result_lines:
    print(line)

二,执行cmd命令

代码语言:javascript复制
import subprocess

cmd = "ffmpeg -i bb_short.mp4 -vf "select='eq(pict_type,  PICT_TYPE_I)'" -vsync vfr out%d.png"
p = subprocess.Popen(cmd, shell=True)
p.wait()
cmd

0 人点赞