在 swf 文件上自动 运行 多个终端程序命令,然后使用 python 打印结果

auto run multiple terminal program commands on a swf file then print results using python

我想制作一个 python 文件,该文件采用 swf 文件名并在终端中针对 3 个程序 trid(检查是否压缩)、flasm(解压缩)、swfdump(转储)和打印运行它将日志输出到文本文件。

例如。终端命令: trid -v filename.swf

是否可以自动执行终端命令?如果是这样,如何编写终端命令,如上面 python?

谢谢!

对于简单的操作,总有os.system。为了获得更大的灵活性,您可以查看 subprocess 模块。

import os

os.system("trid -v filename.swf")
from subprocess import call, check_output

swf_file  = "filename.swf"
dump_file = "dump_swf.txt"

# run TrID on file and get results
result_string = check_output(["trid", "-v", filename])

# parse result_string - is it compressed?
??? YOUR CODE GOES HERE ???

if is_compressed:
    # decompress it
    call(["flasm", "-x", filename])

# decompile it
dump = check_output(["swfdump", "-D", filename])

# save the decompiled result
with open(dump_file, "w") as outf:
    outf.write(dump)