Output an error according to the customary code of the past Python2
1 #-*-coding:utf-8-*-2 " "3 Created on July 21, 20184 5 @author: Lenovo6 " "7 ImportOS8 ImportSYS9 ImportsubprocessTen fromUiautomatorImportDevice as D Onecmd = r'adb install f:\ listening. APK' Ainfo = subprocess.check_output (cmd). Split ("\ r \ n") - Print(info)
Output as follows, error
1 Traceback (most recent): 2 " C:\Users\lenovo\eclipse-workspace\WOO\src\debug\debug1.py " in <module>3 info = subprocess.check_output (cmd). Split ("\ r \ n " )4is not'str'
The query Python3 document has the following description:
By default, this function would return the data as encoded bytes. The actual encoding of the output data may depend in the command being invoked, so the decoding to text would often need to Be handled at the application level. That is, the return is actually an encoded bit value, the actual encoding format depends on the command called, so python3 the decoding process to the application layer, that is, we use the person to do.
Verify that the process is not so, we print out the type of the Subprocess.check_output () as follows, indeed for the bytes type, need to be artificially converted once to string
1 #-*-coding:utf-8-*-2 " "3 Created on July 21, 20184 5 @author: Lenovo6 " "7 ImportOS8 ImportSYS9 ImportsubprocessTen fromUiautomatorImportDevice as D Onecmd = r'adb install f:\ listening. APK' Ainfo =subprocess.check_output (cmd) - Print(Type (info))
The output is as follows:
<class'bytes'>
The correct is as follows:
1 #-*-coding:utf-8-*-2 " "3 Created on July 21, 20184 5 @author: Lenovo6 " "7 ImportOS8 ImportSYS9 ImportsubprocessTen fromUiautomatorImportDevice as D Onecmd = r'adb install f:\ listening. APK' Ainfo =subprocess.check_output (cmd) -Info1 =Info.decode () - Print(Info1.split ('\ r \ n'))
The output is as follows:
[' Success ', ']
[Python3]subprocess.check_output () The output of the Python3 is bytes instead of a string, and a decoding process is added during the actual use Decode (), otherwise there will be a problem