stdout is going to stderr while using subprocess.Popen

0

I am making a tool which will get the password of a wifi network from the mac's system keychain and it seemed to run fine with this code:

import subprocess, time
p = subprocess.Popen('''echo 'mypassword' | /usr/bin/sudo -S security find-generic-password -D "AirPort network password" -a "myssid" -g''', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
input('press enter when you have authed or to cancel if you have not authed')
print(p.stdout.read())

But this code did not output the the wifi password, but more rather

keychain: "/Library/Keychains/System.keychain"
version: 256
class: "genp"
attributes:
    0x00000007 <blob>="Magic house"
    0x00000008 <blob>=<NULL>
    "acct"<blob>="Magic house"
    "cdat"<timedate>=0x32303138313230383039343633375A00  "20181208094637Z\000"
    "crtr"<uint32>=<NULL>
    "cusi"<sint32>=<NULL>
    "desc"<blob>="AirPort network password"
    "gena"<blob>=<NULL>
    "icmt"<blob>=<NULL>
    "invi"<sint32>=<NULL>
    "mdat"<timedate>=0x32303138313230383039343633375A00  "20181208094637Z\000"
    "nega"<sint32>=<NULL>
    "prot"<blob>=<NULL>
    "scrp"<sint32>=<NULL>
    "svce"<blob>="AirPort"
    "type"<uint32>=<NULL>

In terminal, when I add

| grep "password: "

to the end of the command, it outputs:

password: mywifipassword

when I add the pipeline and grep to the subprocess command, it outputs nothing to stdout and

Password:\n password: mywifipassword

For those wondering, the first Password:\n is from sudo. My question is simple: How can I make the password: mywifipassword output to stdout

python-3.x
macos
subprocess
asked on Stack Overflow May 23, 2019 by AirKetchup

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0