gpt4 book ai didi

Python 子进程访问被拒绝

转载 作者:太空宇宙 更新时间:2023-11-03 17:34:22 27 4
gpt4 key购买 nike

我正在尝试使用 python 脚本在后台静默安装 java。路径正确并通过 isfile 验证。我收到拒绝访问异常。我在本地计算机上以管理员身份运行此程序。

subprocess.Popen('C:\Users\xUser\jdk-8u45-windows-x64.exe /s ADDLOCAL="ToolsFeature,SourceFeature"');

错误返回

WindowsError: [Error 5] Access is denied

最佳答案

您在常规终端中运行它吗?在Windows中,需要专门打开终端以获得管理权限:

  1. 在“开始”菜单搜索窗口中,输入 cmd,然后按 Ctrl+Shift+Enter。或者,导航到“所有程序”>“附件”> 右键单击​​“命令提示符”,然后单击以管理员身份运行
  2. 在这个新终端中运行 python 脚本。

编辑:搜索结果显示,导航到安装程序所在目录后执行命令也可能出现问题;请参阅WindowsError [error 5] Access is denied .

install_dir=r"C:\Users\xUser\"
assert os.path.isdir(install_dir)
os.chdir(install_dir)
subprocess.Popen('jdk-8u45-windows-x64.exe /s ADDLOCAL="ToolsFeature,SourceFeature"')

最后,我总是使用 Unix 的一组命令(不确定 Windows 中是否需要),而不是一个长字符串,例如

subprocess.Popen(['jdk-8u45-windows-x64.exe', '/s', 'ADDLOCAL="ToolsFeature,SourceFeature"'])

关于Python 子进程访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31416676/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com