无法使用python调用exe

Vic*_*cky 0 python

我正在调用一个exe(它依赖于其他批处理文件),Python正在给出错误.我能够调用exe(这是独立的)

我在做什么..

import os
os.system("notepad.exe")    # is working
Run Code Online (Sandbox Code Playgroud)

os.system("c:/ank.exe")     # this is giving error as ank.exe is dependent on other batch     files
Run Code Online (Sandbox Code Playgroud)

Adr*_*son 5

您必须首先更改当前目录,以便您要运行的可执行文件可以找到其依赖项:

target = "c:/ank.exe"
os.chdir(os.path.dirname(target))
os.system(target)
Run Code Online (Sandbox Code Playgroud)

否则,os.system()在正在运行的脚本的目录中执行.