[英]How to strip special characters from the start and end of the string in python
[英]How to strip and removed special characters from the out put of python sub process
我正在使用Python子进程执行命令如下图:
process = subprocess.Popen(['debug', 'file.tgz'],
stdout=subprocess.PIPE,stderr=subprocess.PIPE)
while True:
output = process.stdout.readline()
print(str(output.strip()).encode())
return_code = process.poll()
if return_code is not None:
break
我得到的内容如下所示:
b"b'Registers:'"
这就是我所期待的。
Registers:
我正在使用编码,但仍然看到相同的输出。 如果我在命令行上运行相同的进程,我会得到相同的期望输出。
如何删除这些特殊字符?
b'...'
print(output.decode('utf8', errors='strict').strip())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.