将参数传递给subprocess.call

2024-09-29 21:33:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我在无声安装某些程序时遇到了不愉快的情况。我不确定他们是否对带有值的安装标志使用了任何约定,但以下是安装应使用的内容:

"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}"']

子流程正在执行的命令(从子流程获取。list2cmdline(命令))是:

setup.exe" -uninst -s -f2\"some path\temp build 12\uninstall.log\"

基本上会出现斜杠,安装失败。 理论上,我可以创建自己的字符串,但另一个可执行文件的同一个提供程序提供了另一种与子进程更兼容的语法。我想知道是否有可能设置一个参数列表来满足安装程序的要求


Tags: path命令程序log内容标志withsetup
1条回答
网友
1楼 · 发布于 2024-09-29 21:33:25

如果你跑

"path with spaces\setup.exe" -uninst -s -f2"path with spaces\uninstall.log"

从命令行,对subprocess.call的等效调用是

uninstall_log_file = r"path with spaces\uninstall.log"
command = [self.setup_exe, '-uninst', '-s', f'-f2{uninstall_log_file}']
subprocess.call(command)

相关问题 更多 >

    热门问题