Moode Forum
[PROBLEM] gpio-buttons.py: subprocess.call(...) not working - workaroud found - Printable Version

+- Moode Forum (http://moodeaudio.org/forum)
+-- Forum: moOde audio player (http://moodeaudio.org/forum/forumdisplay.php?fid=3)
+--- Forum: Support (http://moodeaudio.org/forum/forumdisplay.php?fid=7)
+--- Thread: [PROBLEM] gpio-buttons.py: subprocess.call(...) not working - workaroud found (/showthread.php?tid=2454)



gpio-buttons.py: subprocess.call(...) not working - workaroud found - m-hoefling - 05-01-2020

Hey,

i am new to moode and this forum, but as i faced an issue i would like to share this with you.
While i tried to configure external buttons to controll volume on my setup which is:
Moode version: Release 6.5.1 2020-04-27

In the GPIO Config panel i configured Button 1 on Pin 5 to cmd mpc vol +5
While testing this with /var/www/command/gpio-buttons.py
i figured out that an exception was raised as follows:

Code:
2020-05-01 14:19:39 sw_1: pin=5, enabled=1, bounce_time=1000, cmd=mpc vol +5
Traceback (most recent call last):
 File "/var/www/command/gpio-buttons.py", line 58, in sw_1_event
   subprocess.call(sw_1_cmd)
 File "/usr/lib/python2.7/subprocess.py", line 172, in call
   return Popen(*popenargs, **kwargs).wait()
 File "/usr/lib/python2.7/subprocess.py", line 394, in __init__
   errread, errwrite)
 File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child
   raise child_exception
OSError: [Errno 2] No such file or directory
 

I could solve this issue by adding the shell=True argument so tat the callbacks look like this:
Code:
def sw_1_event(channel):
   subprocess.call(sw_1_cmd, shell = True)

But according to https://docs.python.org/2/library/subprocess.html#frequently-used-arguments this option might be not the best because in fact for moode the command string is constructed from external input (GPIO COnfig panel)

Is there someone else facing this issue and what do you think about the solution?


RE: gpio-buttons.py: subprocess.call(...) not working - workaroud found - Tim Curtis - 05-01-2020

There is a NOTE under the save button on the GPIO Config screen.
NOTE: Use a comma to delimit arguments in the CMD field. Example: mpc,load,My Playlist

Your entry should be mpc,vol,+5 but it could be improved by doing below which would also update the UI volume knob.

/var/www/vol.sh,up,5