0

I am puzzled as to why the following script (count.py) will not run using the IR remote

#!/usr/bin/env python
from __future__ import with_statement
with open('num.txt','r+') as f:
   counter = str(int(f.read())+1)
   f.seek(0)
   f.write(counter)

I have other scripts which work fine i.e. this one when mapped to same button executes without issue

#!/usr/bin/env python
import RPi.GPIO as GPIO ## Import GPIO library
GPIO.setmode(GPIO.BCM) ## Use board pin numbering
GPIO.setup(22, GPIO.OUT) ## Setup GPIO Pin 7 to OUT
GPIO.output(22,True) ## Turn on GPIO pin 7
GPIO.cleanup()

The problem script will work from the command line using 'sudo python count.py' and if I start irexec from the command line with sudo then it will also run using the remote. In essence starting irexec in this way is a workable solution. Nevertheless I am still keen to establish why under the present conditions the script will not run.

Nick C
  • 79
  • 8
  • The indenting as shown is incorrect, it needs to be indented under the `with` statement. – Martin Evans Sep 20 '15 at 08:21
  • have you check the file permissions of `num.txt` to ensure it's both readable and writable by the user that executes the script without sudo? – Joe Young Sep 20 '15 at 08:40
  • @Joe - It has full priviledges. I have run 'sudo Chmod 777' on the whole folder containing it. – Nick C Sep 20 '15 at 08:45

1 Answers1

0

It might be that the problem script is not able to open "num.txt": either it is running as a user who doesn't have permission, or it is running from a directory you don't expect and so can't see the relative path to num.txt. In this case the script would fail with an error, but this might be being lost somewhere.

Try checking logs to see if there are any errors reported.

You can also alter the script to use an absolute path to num.txt, and catch exceptions and write them to a log somewhere (also absolute path, and all write permissions? - maybe in /tmp)

Douglas Leeder
  • 52,368
  • 9
  • 94
  • 137
  • I put the absoute path to num.txt in the script and it now seems to be working. Many thanks! – Nick C Sep 20 '15 at 08:59