I have this bash script I want to call directly from Python:
#!/bin/bash
for usb in $(ls /dev/ttyUSB*); do echo $(udevadm info $usb | grep ID_SERIAL= | cut -d ' ' -f 2) $usb; done
I'm getting error on the very first section:
from subprocess import Popen
Popen('ls /dev/ttyUSB*'.split())
I understand that this is due to Popen running sh
, and it does not support wildcard, so I tried invoking bash
with:
from subprocess import Popen
Popen('/bin/bash ls /dev/ttyUSB*'.split())
OR
Popen('/bin/bash "ls /dev/ttyUSB*"'.split())
but got
/bin/ls: /bin/ls: cannot execute binary file
However, the files do exist:
ls /dev/ttyUSB*
outputs: /dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 /dev/ttyUSB3
After solving this, I still have to understand how can I use a pipe in the middle of () [i.e. - for usb in $(ls /dev/ttyUSB*); do echo $(udevadm info $usb | grep