1

I'm trying to find a specific string from a command output in terminal. It doesn't work however.

Here is the command I'm running:

check = subprocess.check_output("netctl list | sed -n 's/^\* //p'", shell=True)

That brings back one of two things. If you are not connected, it returns b'', otherwise it returns b'$networkname\n'.

The code I'm using to check it follows:

p = re.compile(r"\bb''\b")
if p.search("b''"):
    print("False")
    return False
else:
    print("True")
    return True

However, it returns true no matter what. I've also tried:

if check == "b''":

but that also returns true no matter what. I'm losing my mind here. What is causing it not to work?

0

1 Answer 1

2

The fact is that you should be looking for the empty bytes literal b'', not the string "b''".

if check == b'':
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.