Python 3.x 如何在Python中使用subprocess.Popen返回编码值?
有人能告诉我如何对return语句进行编码以便它能够解码吗。 或者需要更改什么才能获得编码值 代码 输出Python 3.x 如何在Python中使用subprocess.Popen返回编码值?,python-3.x,subprocess,popen,with-statement,Python 3.x,Subprocess,Popen,With Statement,有人能告诉我如何对return语句进行编码以便它能够解码吗。 或者需要更改什么才能获得编码值 代码 输出 Popen.communicate返回一个(stdout,stderr)的元组,因此您需要将返回值视为: stdout, stderr = run_process(cmd_args); print(stdout) print(stdout.decode("utf-8")) 有关更多详细信息,请阅读。不是返回过程通信(),而是返回过程通信()[0]。 因为proc.communicate()
Popen.communicate
返回一个(stdout,stderr)
的元组,因此您需要将返回值视为:
stdout, stderr = run_process(cmd_args);
print(stdout)
print(stdout.decode("utf-8"))
有关更多详细信息,请阅读。不是返回过程通信(),而是返回过程通信()[0]。
因为proc.communicate()是一个输出和错误列表,似乎您只需要输出部分就可以了@blhsing,非常感谢stdout,stderr=run\u进程(cmd\u args);这对我有帮助。
print(res.decode("utf-8"))
AttributeError: 'tuple' object has no attribute 'decode'
stdout, stderr = run_process(cmd_args);
print(stdout)
print(stdout.decode("utf-8"))