I want to run the following lines of linux bash
commands inside a python program.
tail /var/log/omxlog | stdbuf -o0 grep player_new | while read i
d
Here is a pure python solution that I think does the same as your bash
:
logname = '/var/log/omxlog'
with open(logname, 'rb') as f:
# not sure why you only want the last 10 lines, but here you go
lines = f.readlines()[-10:]
for line in lines:
if 'player_new' in line:
omxd = os.popen('omxd S').read()
after_ = omxd[line.rfind('_')+1:]
before_dot = after_[:after_.rfind('.')]
print(before_dot)