Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在Python中使用subprocess.Popen返回编码值?_Python 3.x_Subprocess_Popen_With Statement - Fatal编程技术网

Python 3.x 如何在Python中使用subprocess.Popen返回编码值?

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()

有人能告诉我如何对return语句进行编码以便它能够解码吗。 或者需要更改什么才能获得编码值

代码

输出


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"))