You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Windows中运行无.exe后缀的可执行文件并正确传递参数

问题原因

当前写法参数被忽略是subprocess.Popen的参数传递逻辑导致的:

  • 当你显式指定executable参数、同时第一个args参数为字符串且开启shell=True时,Windows 系统下args的内容会被识别为 shell 的输入参数,而非你指定的C:\abc的运行参数,因此参数没有传递到目标程序。
解决方案

方案1(更推荐,无需开启shell)

直接把程序路径和所有参数都放在第一个args列表中,不需要指定executable,也不需要开启shell=True,同时避免了 shell 注入风险:

import subprocess
subprocess.Popen([r"C:\abc", "-a", "-b", "-c"], creationflags=0x08)

方案2(必须保留shell=True时可用)

如果你的场景必须开启shell,有两种修改方式:

  • 把可执行程序路径和参数合并写在args中,不需要单独指定executable:
import subprocess
subprocess.Popen(r'C:\abc -a -b -c', creationflags=0x08, shell=True)
  • 保留executable参数,将args第一个位置设为空字符串,后续放程序的运行参数:
import subprocess
subprocess.Popen(['', '-a', '-b', '-c'], creationflags=0x08, shell=True, executable=r"C:\abc")

Windows CMD 直接运行方法

打开CMD后直接输入完整路径加参数即可运行,无后缀不影响执行:

C:\abc -a -b -c

内容的提问来源于stack exchange,提问作者yuriarthas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 23:27:03