python output from subprocess.Popen

Given that I'm a python beginner, I'm trying to write a simple software to scan some bluetooth devices (beacon with advertising) and I have a problem with the instruction subprocess.Popen. When I execute the following code:

...

p1 = subprocess.Popen(['timeout','10s','hcitool','lescan'],stdout=subprocess.PIPE,stderr=subprocess.PIPE)

p1.wait()
output, error = p1.communicate()
print("stdout: {}".format(output))
print("stderr: {}".format(error))

...

the output and error variables are empty! If I remove the "stdout=subprocess.PIPE,stderr=subprocess.PIPE" from the Popen I can see the right result in the console, if I change the command with ['ls','-l'] it works fine and I see the result in the variables . I've tryed with subprocess.run (with the timeout) and it is the same. If I don't use the timeout obviously the command never ends. I can't use pybluez and my python version is the 3.7 Can someone help me?



Read more here: https://stackoverflow.com/questions/65709718/python-output-from-subprocess-popen

Content Attribution

This content was originally published by claudio martellini at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: