首页 > 解决方案 > 打开可执行文件的前置路径

问题描述

我正在使用 popen 在 windows vm 上运行以下命令

'tf 变更集 ...'

但是当我使用它运行它时

commandLine = 'tf changeset /noprompt /latest /loginType:OAuth /login:.,***'

process = Popen(commandLine, shell=True, stdout=PIPE, stderr=PIPE)

我在日志中看到以下内容正在执行

'C:\Azure\Agent-1/externals/tf/tf 变更集 ...'

这意味着 'C:\Azure\Agent-1/externals/tf/' 已预先添加到我的命令中。我只是期待看到

'tf 变更集 ...'

不幸的是,添加执行路径会破坏命令,有没有办法阻止 python 这样做?

标签: pythonpython-3.x

解决方案


尝试将commandLinetoPopen作为参数列表传递:

commandLine = ["tf", "changeset", "/noprompt", "/latest", "/loginType:OAuth", "/login:.,***'"]
process = Popen(commandLine, stdout=PIPE, stderr=PIPE)

推荐阅读