Home > other >  Python using Popen.com municate tuples return an error
Python using Popen.com municate tuples return an error

Time:03-19

Python using Popen.com municate return an error tuple, please everyone a great god help to see what this is about, how to change

The code is as follows:
PATH=lambda p: OS. PATH. Abspath (
OS. The path. The join (OS) path) dirname (__file__), p)
)
Apkpath=PATH ("../appiumnautomaster/img/YYHL_Android_V1_2_5_ver_d0505. Apk ")

Def get_apk_pkg () :
CMD="aapt dump badging" + apkpath + "| grep package:"
Result=""
P=subprocess. Popen (CMD, stdout=subprocess. PIPE,
Stderr=subprocess. PIPE,
Stdin=subprocess. PIPE shell=True)
Print (p.com municate ())
(the output, err)=p.com municate ()
If the output!="" :
Result=output. The split () [1]. The decode () [6:1]
Print (result)
Return the result
Print (get_apk_pkg ())

Program to use appt dump badging command parsing apk, get apk package name
When running the code, printing p.com municate () is this:
(b ', b 'aapt \ "sets \ XBB \ xca \ xc7 \ xc4 \ xda \ sets \ XBF \ XBB \ xf2 \ XCD \ xe2 \ sets \ XBF \ xc3 \ XFC \ xc1 \ xee \ xa3/xac/xd2, sets, sets, XBB \ xca \ xc7 \ XBF \ xc9 \ xd4 \ XCB \ xd0 \ xd0 \ xb5 \ xc4 \ xb2 \ XCC \ xd0 \ xf2 \ r \ n \ XBB \ xf2 \ xc5 \ xfa \ xb4 \ xa6 \ xc0 \ xed \ xce \ xc4 \ XBC \ xfe \ xa1 \ xa3 \ r \ n")
But look at the tutorial return tuple format should be: (stdoutdata, stderrdata); That is to say stdoutdata corresponding b '; This was not ah, debugging for a long time didn't solve
The great god, please help to look at, solve, thank you very much

CodePudding user response:

Print CMD, performed manually to see if you have any questions

CodePudding user response:

Directly on the pycharm when running the code will return tuples (b ', b 'aapt \ sets \ "XBB \ xca \ xc7 \ xc4 \ xda \ sets \ XBF \ XBB \ xf2 \ XCD \ xe2 \ sets \ XBF \ xc3 \ XFC \ xc1 \ xee \ xa3/xac/xd2, sets, sets, XBB \ xca \ xc7 \ XBF \ xc9 \ xd4 \ XCB \ xd0 \ xd0 \ xb5 \ xc4 \ xb2 \ XCC \ xd0 \ xf2 \ r \ n \ XBB \ xf2 \ xc5 \ xfa \ xb4 \ xa6 \ xc0 \ xed \ xce \ xc4 \ XBC \ xfe \ xa1 \ xa3 \ r \ n")
But print CMD input command line prompt grep not internal command; How can you make the grep internal command (win10 system); If not why internal commands that run on pycharm error can not return tuple
?Then I change the grep to find to the command line can get the right package (package: name='com. Example. Monkneytest' versionCode='1' versionName='1.0'); But run on pycharm return tuples and use grep return tuples identical

CodePudding user response:

The
reference 1/f, CKC response:
print CMD, performed manually to see if you have any questions


Directly on the pycharm when running the code will return tuples (b ', b 'aapt \ sets \ "XBB \ xca \ xc7 \ xc4 \ xda \ sets \ XBF \ XBB \ xf2 \ XCD \ xe2 \ sets \ XBF \ xc3 \ XFC \ xc1 \ xee \ xa3/xac/xd2, sets, sets, XBB \ xca \ xc7 \ XBF \ xc9 \ xd4 \ XCB \ xd0 \ xd0 \ xb5 \ xc4 \ xb2 \ XCC \ xd0 \ xf2 \ r \ n \ XBB \ xf2 \ xc5 \ xfa \ xb4 \ xa6 \ xc0 \ xed \ xce \ xc4 \ XBC \ xfe \ xa1 \ xa3 \ r \ n")
But print CMD input command line prompt grep not internal command; How can you make the grep internal command (win10 system); If not why internal commands that run on pycharm error can not return tuple
?Then I change the grep to find to the command line can get the right package (package: name='com. Example. Monkneytest' versionCode='1' versionName='1.0'); But run on pycharm return tuples and use grep return tuples as like as two peas

CodePudding user response:

The
reference 1/f, CKC response:
print CMD, performed manually to see if you have any questions


Sorry, brother, I change the grep to find and then by the way, can return the correct tuples,
Online has examined the grep like liunxs system command, this command is not directly under win10 system use, still need to installation instructions tools can use

CodePudding user response:

Def get_apk_pkg (self) :
CMD="aapt dump badging" + self apkpath + "| findstr searches package:"
Print (CMD)
Result=""
P=subprocess. Popen (CMD, stdout=subprocess. PIPE,
Stderr=subprocess. PIPE,
Stdin=subprocess. PIPE shell=True)
(the output, err)=p.com municate ()
If the output!="" :
Print (p)
Print (' * * * * * * * * * * * ')
Print (the output)
Result=output. The split () [1]. The decode () [6:1]
Print (result)
Return the result
I'm or error
List index out of range

B "' aapt \ sets \ XBB \ xca \ xc7 \ xc4 \ xda \ sets \ XBF \ XBB \ xf2 \ XCD \ xe2 \ sets \ XBF \ xc3 \ XFC \ xc1 \ xee \ xa3 \ xac \ xd2, sets, sets, XBB \ xca \ xc7 \ XBF \ xc9 \ xd4 \ XCB \ xd0 \ xd0 \ xb5 \ xc4 \ xb2 \ XCC \ xd0 \ xf2 \ r \ n \ XBB \ xf2 \ xc5 \ xfa \ xb4 \ xa6 \ xc0 \ xed \ xce \ xc4 \ XBC \ xfe \ xa1 \ xa3 \ r \ n"

CodePudding user response:

Did you solve the problem?

CodePudding user response:

36073160 references 5 floor response:
def get_apk_pkg (self) :
CMD="aapt dump badging" + self apkpath + "| findstr searches package:"
Print (CMD)
Result=""
P=subprocess. Popen (CMD, stdout=subprocess. PIPE,
Stderr=subprocess. PIPE,
Stdin=subprocess. PIPE shell=True)
(the output, err)=p.com municate ()
If the output!="" :
Print (p)
Print (' * * * * * * * * * * * ')
Print (the output)
Result=output. The split () [1]. The decode () [6:1]
Print (result)
Return the result
I'm or error
List index out of range

B "' aapt \ sets \ XBB \ xca \ xc7 \ xc4 \ xda \ sets \ XBF \ XBB \ xf2 \ XCD \ xe2 \ sets \ XBF \ xc3 \ XFC \ xc1 \ xee \ xa3 \ xac \ xd2, sets, sets, XBB \ xca \ xc7 \ XBF \ xc9 \ xd4 \ XCB \ xd0 \ xd0 \ xb5 \ xc4 \ xb2 \ XCC \ xd0 \ xf2 \ r \ n \ XBB \ xf2 \ xc5 \ xfa \ xb4 \ xa6 \ xc0 \ xed \ xce \ xc4 \ XBC \ xfe \ xa1 \ xa3 \ r \ n"
hello, did you solve the problem, how to solve
  • Related