I can't make heads or tails of this one. Trying to use subprocess in python script to scrape my wifi signal via iw
. The terminal command works fine:
root@123da06:/app# iw dev wlan0 link | grep signal | awk '{print $2}'
-62
But fails when trying to run it in python:
root@123da06:/app# python3 sub.py
Traceback (most recent call last):
File "sub.py", line 2, in <module>
output_bytes = subprocess.check_output("iw dev wlan0 link | grep signal | awk '{print $2}'")
File "/usr/local/lib/python3.8/subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/local/lib/python3.8/subprocess.py", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/local/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: "iw dev wlan0 link | grep signal | awk '{print $2}'"
The script couldn't be simpler:
import subprocess
output_bytes = subprocess.check_output("iw dev wlan0 link | grep signal | awk '{print $2}'")
output = output_bytes.decode("utf-8")
print(f'Signal: {output}')
What am I doing wrong?