与其他功能模块例如pandaspython一起使用时,os.system调用不起作用

问题描述

我正在尝试使用os.system()并获得管理员权限来在Python中为可执行文件执行命令。

这是完全有效的代码

import ctypes,sys
def is_admin():
 try:
    return ctypes.windll.shell32.IsUserAnAdmin()
 except:
    return False

if is_admin():
 import os
 os.chdir(os.path.dirname(os.path.abspath(r'C:\Users\XXXX\XXXX\XXXXX')))
 #print(os.getcwd())
 a= 4331
 os.system( r'XXX.exe --file "input_directory" --output "Output_directory" --start {} --end {}'.format(a,a))

else:
# Re-run the program with admin rights
 ctypes.windll.shell32.ShellExecuteW(None,"runas",sys.executable," ".join(sys.argv),None,1)

但是,如果我尝试运行相同的代码,而不是从Pandas数据帧加载时为变量-a提供输入,并加载变量的值,如下所示

import ctypes,sys
def is_admin():
 try:
    return ctypes.windll.shell32.IsUserAnAdmin()
 except:
    return False

if is_admin():
   import pandas as pd
   df=pd.read_excel(r'D:XXXX',sep=',')
   for i in df['framenumber']:
    import os
    os.chdir(os.path.dirname(os.path.abspath(r'C:\Users\XXXX\XXXX\XXXXX')))

#print(os.getcwd())
    os.system( r'XXXX.exe --file "input_directory" --output "Output_directory" --start {} --end {}'.format(i,i))


else:
# Re-run the program with admin rights
 ctypes.windll.shell32.ShellExecuteW(None,1)

当我接受输入时,这不起作用(变量来自Pandas。我不明白为什么?有什么解决办法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)