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

2024-04-20 14:02:50 发布

您现在位置:Python中文网/ 问答频道 /正文

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

例如,终端中的命令: 三角-v文件名.swf你知道吗

有没有可能自动化终端命令?如果是这样的话,如何编写一个终端命令,就像上面用python编写的那样?你知道吗

谢谢!你知道吗


Tags: 文件命令程序终端文件名swf文本文件trid
2条回答

对于简单的选择,总是有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)

相关问题 更多 >