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?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Cody Dostal
  • 311
  • 1
  • 3
  • 13

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
  • 128,818
  • 30
  • 231
  • 230
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358