从python打开.bat

我有一个名为abcexport.exe exe文件夹中的.bat文件,其中包含以下代码:

 abcexport.exe myswf.swf 

在窗口上双击蝙蝠通常会按预期方式导出swf

我需要从Python内部做到这一点,但它抱怨abcexport是“不被认为是一个内部或外部的命令”。

我的代码:

尝试1 –

 os.startfile("path\\decompiler.bat") 

尝试2 –

 subprocess.call([path\\decompiler.bat"]) 

也尝试了与os.system()subprocess os.system()方法os.system()相同,并传递参数shell=True结束在同一

你可以使用这个

 from subprocess import Popen p = Popen("batch.bat", cwd=r"C:\Path\to\batchfolder") stdout, stderr = p.communicate() 

.bat文件不可执行。 您必须使用cmd.exe(解释器)“运行它”。 尝试

 import subprocess executable="path\\decompiler.bat" p = subprocess.Popen(["C:\Windows\System32\cmd.exe", executable, 'myswf.swf'], shell=True, stdout = subprocess.PIPE) p.communicate() 

按照.bat的顺序工作