python - 具有多个参数、变量和当前工作目录的命令行

标签 python shell python-3.x command-line command-line-arguments

我正在尝试使用 Popen 调用命令行。

命令行在shell中操作

cd C:\Program Files (x86)\Inventor
Inventor -exe -- no-gui -f C:\Users\Vince\Documents\Inventor\Inventor.iam

但是当我在程序中使用 Popen 尝试时

from subprocess import *
from os.path import expanduser

home = expanduser("~")
path = home + "\\Documents\\Inventor\\Inventor.iam"
cmd = "Inventor -exe -- no-gui -f " + path
Popen(cmd, cwd="C:\\Program Files (x86)\\Inventor")

它返回给我FileNotFoundError: [WinError 2]

所以我无法弄清楚文件路径出了什么问题。

最佳答案

在参数中添加 (shell =True)

但请谨慎使用 warning for using shell = True argument

关于python - 具有多个参数、变量和当前工作目录的命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31134128/

相关文章:

python - Pygame 导致低 FPS。如何提高性能?

python - Python 有流式正则表达式模块吗?

python pandas.loc 找不到行名称 : KeyError

python - 获取 zip 文件中的文件夹名称 - Python

python - 使用电子表格数据时如何避免嵌套循环?

linux - 如果 wc -l 没有行尾字符,则不计算文件的最后一个

linux - 尝试使用 trap 跳出 shell 函数

python - django.core.exceptions.AppRegistryNotReady : Apps aren't loaded yet. 文件初始化

python - 优化在一长串字符串中的搜索

shell - 管道输入到脚本中