使用python3运行批处理脚本

时间:2018-10-29 13:58:07

标签: batch-file python-3.6

我正在尝试使用Python3执行批处理文件。在批处理文件还需要路径作为参数的地方(我不能共享批处理脚本,因为它非常机密。相信我,因为可以从cmd执行文件,所以批处理脚本中没有错误)。我正在使用来自子流程模块的Popen,并从几篇在线文章中获得了帮助。

我的代码如下:

from subprocess import Popen
        def start_A(path):
            try:
                Popen(['c:\windows\system32\cmd.exe','A.bat',path], cwd=path,shell=True)
    #path is the argument variable which I am sending
            except Exception as e:
                m.showerror(title="A",message=str(e))

        def start_B(path):
            try:
                Popen(['c:\windows\system32\cmd.exe','B.bat',path], cwd=path,shell=True)

            except Exception as e:
                m.showerror(title="B",message=str(e))

当我运行以上代码时,批处理脚本无法执行。它既不显示任何错误,也不显示任何异常。我希望我的cmd弹出并完成执行。

0 个答案:

没有答案