【发布时间】:2014-07-23 10:31:02
【问题描述】:
命令提示符:
C:\Users\Documents\libexe\tfc\bin\Debug>asc-dir
asc-dir.: directory not linked to an ASC directory //Expected output
测试脚本:
proc = subprocess.Popen('asc-dir', stdout=subprocess.PIPE, shell = True)
(result, err) = proc.communicate()
这会将“asc-dir.: directory not linked to an ASC directory”打印到控制台,但不会保存到result 或err。
如何将输出保存到 result / err?
当我尝试 Popen 和 shell=False 时,我收到以下错误:
Error:
WindowsError: [Error 2] The system cannot find the file specified
Press any key to continue . . .
【问题讨论】:
-
>您需要在 Windows 上指定 shell=True 的唯一情况是当您希望执行的命令内置于 shell 中时(例如
dir或copy)您真的需要吗? -
正如我所说,当 shell=False 时,我在问题的底部得到错误。
-
@Jahaja:
shell=Trueandshell=Falsediffer in how the executable is found on Windows。对于shell=False,OP 可能需要明确提供扩展,例如'asc-dir.cmd'。