【发布时间】:2020-06-19 13:05:18
【问题描述】:
我在静默安装某些程序时遇到了不愉快的情况。我不确定他们是否对带有值的安装标志使用任何约定,但这里应该使用什么进行安装:
"path with spaces\setup.exe" -uninst -s -f2"path with spaces\uninstall.log"
您不能使用 --f2="path with spaces\uninstall.log" 或 -f2="path with spaces\uninstall.log" 或 -f2 "path with spaces\uninstall.log"
所以如果我在 Python 中使用以下:
command = [self.setup_exe, '-uninst', '-s', fr'-f2"{uninstall_log_file}"']
子进程正在执行的命令(从subprocess.list2cmdline(command)获取)是:
setup.exe" -uninst -s -f2\"some path\temp build 12\uninstall.log\"
基本上会出现斜线并且安装失败。 从理论上讲,我可以创建自己的字符串,但另一个可执行文件的相同提供程序提供了另一种与子进程更兼容的语法。我想知道是否可以设置一个参数列表来满足安装程序的要求?
【问题讨论】:
-
您实际上是如何调用命令的?看起来您可能在不应该使用
shell=True时使用。 -
@chepner,你是对的,我使用的是 shell=True。据我了解,如果我需要以提升用户身份运行命令(例如使用 PowerShell),则需要这样做。或者它会在任何情况下工作吗?
-
不,使用
shell=True只是从直接执行命令切换到运行带有构造参数的shell,让shell 为您运行命令。 -
这是我现在的调用方式:subprocess.call(command)
-
@chepner,现在它正在创建另一层引号:"-f2\"some path\uninstall.log\""
标签: python subprocess silent-installer