0

I have scripted two python codes. one, to run on boot and to create a file locally in the same directory where the code is placed another one to sense a low to high signal in GPIO. I have placed the code at /etc/rc.local. I'm trying something like this.

sleep 1; python /home/ubuntu/Desktop/lcd.py &
sleep 1; python /home/ubuntu/Desktop/button.py
exit 0 

Both the codes , runs on boot and no issue with that. The problem I'm facing is that the first code " lcd.py" should create a local file and THE FILE HAS NOT BEEN CREATED. I have searched for the existence of file in both the /etc directory and the path of the python script. Can someone help me fix this problem?

0

Scripts in /etc/rc.local run in / afaik. You should change the working directory or provide an absolute path in your python script.

  • I could not get You as I'm new to linux. Can you please elaborate? – RLN Apr 22 '14 at 10:41
  • Every process has a working directory (pwd) it 'runs in'. If you do something like open("path/foobar", "w") in python it will interpret path/foobar relative to this working directory. Commands that are executed from /etc/rc.local are running in the root directory / so your file will end up in / if you do not specify an absolute path starting with / like /path/to/file. In a shell you can change the working directory with the cd command, in python with os.chdir(dirname). – Euro Apr 22 '14 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.