获取批处理文件的命令行输出以写入另一个文件

时间:2015-07-04 17:38:48

标签: python windows batch-file python-3.x

我有一个调用批处理文件的python文件。批处理文件写入命令行窗口。如何从python文件中的批处理文件解析该输出到命令行。

我得到的唯一输出是Error on uploading case data: ('unknown', '\x00', 0, 1, '') ['Equals', 'GetHashCode', 'GetType', 'InitializeFromClr', 'Item', 'MemberwiseClone', 'ReferenceEquals', 'ToString', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getslice__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', 'args', 'clsException', 'encoding', 'end', 'message', 'object', 'reason', 'start'] message: --- --- args: --- ('unknown', '\x00', 0, 1, '') --- CLR Exception: --- System.Text.EncoderFallbackException --- Error located in on line 531 in function Error located in on line 410 in function packData... NONE

NONE

1 个答案:

答案 0 :(得分:1)

也许使用命令模块而不是子进程?它会给你命令的结果

import commands
result = commands.getoutput('ls')
print(result)