0

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?

tripleee
  • 158,107
  • 27
  • 234
  • 292
Cody Dostal
  • 191
  • 1
  • 2
  • 12

1 Answers1

2

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

if check == b'':
jamylak
  • 120,885
  • 29
  • 225
  • 225
Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325