【发布时间】:2015-01-04 22:57:18
【问题描述】:
我正在使用子进程通过 findbuild.exe 获取服务器上的构建路径。某些 exe 使用构建字符串在服务器上查找构建。 我将 findbuild.exe 的输出存储在“out”变量中。如下所示
process = subprocess.Popen(findBuild_cmd, stdout=subprocess.PIPE, stderr = subprocess.PIPE)
out,err = process.communicate()
我解析它以获取构建位置并使用
丢弃其余部分sblTemp = str((out.partition("Location: ")[2]).partition("\n")[0])
sblTemp is a network path like \\water\build\12345\123.4\
我想像 \boot\builds\bin\abc.mbn 这样添加偏移量
所以,我想要的最终路径是
\\water\build\12345\123.4\boot\builds\bin\abc.mbn
我使用了 os.path.join 但发现字符串被后面的偏移量覆盖了。
当我试图连接上述两个时,我看到如果我这样做
temp = r"XYZ"+ sbl,它工作正常,但是当我尝试这样做时 temp = sblTemp + r"XYZ" 它会覆盖第一个字符串
你能帮我弄清楚这里出了什么问题吗?
【问题讨论】:
-
你的问题有点混乱。您能否提供一个小代码示例并告诉我们它给出的错误结果是什么?
-
sbl 具有构建路径- temp = "" temp = sbl + r"HELLO" print temp print "" temp = "" temp = r"HELLO" + sbl print temp 输出:HELLOfle\builds41 \INTEGRATION\M4004.2 你好\\waffle\builds41\INTEGRATION\M4004.2
标签: python python-2.7 subprocess string-concatenation