我想制作一个python文件,它接收一个swf文件名并在终端中运行它对3个程序trid(检查是否压缩),flasm(解压缩),swfdump(转储)并将日志打印到文本文件。
离。终端命令: trid -v filename.swf
是否可以自动执行终端命令?如果是这样,如何在python中编写如上所示的终端命令?
谢谢!
答案 0 :(得分:1)
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)
答案 1 :(得分:0)
对于简单的选择,总是os.system
。为了获得更大的灵活性,您可以查看subprocess
模块。
import os
os.system("trid -v filename.swf")