首页 > 解决方案 > 通过子进程python运行praat脚本时无法将字节输出转换为字符串

问题描述

sound_offset_time = subprocess.check_output(praat_command_str, shell=True).decode("utf-8")

给出输出

# Result: - # 

另一个命令

process = subprocess.Popen(praat_command_str, stdout=subprocess.PIPE, stderr=None, shell=True)

给出输出:

('-\x006\x00.\x008\x001\x004\x006\x006\x000\x008\x009\x006\x003\x001\x007\x006\x006\x002\x00\r\x00\n\x00', None)

我无法从字节转换为字符串,仍然获得'-'。正确的输出,如果从命令行运行是

-6.814660896317662

标签: python

解决方案


看起来您的命令正在以utf-16形式发送输出,但您正试图将其解码为utf-8.


推荐阅读