【问题标题】:auto run multiple terminal program commands on a swf file then print results using python在 swf 文件上自动运行多个终端程序命令,然后使用 python 打印结果
【发布时间】:2015-12-16 01:56:23
【问题描述】:

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

例如。终端中的命令: trid -v 文件名.swf

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

谢谢!

【问题讨论】:

  • 你有什么可以包含的,也许是一些导致你的问题的代码,我们可以尝试修复?
  • @ScottKaye - 我没有太多东西,但我被困在如何从 python 代码中调用诸如 trid 之类的程序并传入 args

标签: c# python linux flash ubuntu


【解决方案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)

【讨论】:

  • 您可以使用 check_call 将文件对象传递给标准输出
  • 谢谢!这让我开始了,有没有办法将带有特定 arg 的 grep 传递到 swfdump 以便转储只打印具有特定 arg 传递到 grep 的行?
【解决方案2】:

对于简单的操作,总是有os.system。如需更多灵活性,您可以查看subprocess 模块。

import os

os.system("trid -v filename.swf")

【讨论】:

    猜你喜欢
    • 2021-08-16
    • 1970-01-01
    • 2017-09-04
    • 2011-02-04
    • 1970-01-01
    • 1970-01-01
    • 2016-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多