我想从读取二进制文件中读取并执行二进制calc.exe。
如何在以下脚本中运行code1
file = r"calc.exe"
with open(file, "rb") as code1:
exec(code1)
我不想直接执行calc.exe或在要执行的文件上写code1
TypeError: exec() arg 1 must be a string, bytes or code object
答案 0 :(得分:0)
要从Python运行程序,可以使用subprocess模块。
示例:
import subprocess
proc = subprocess.Popen(r"calc.exe") # calc .exe needs to be availble in the working directory or from the path
outs, errs = proc.communicate(timeout=15)