miaomiao
Posts: 22
Joined: Fri Jun 30, 2017 4:07 am

How to download code to Raspberry Pi to execute at start

Tue Jul 25, 2017 2:41 am

Hi, I am using Raspberry Pi2. And I encountered problem to put code into Raspberry pi,it could work properly in the terminal with LCD on. But if I want Raspberry Pi execute automatically at startup without I click " compile" "make". I tried this five methods still could not work. https://www.dexterindustries.com/howto/ ... t-startup/ Does anyone know how to do? Thank you very much.

User avatar
lmarmisa
Posts: 1265
Joined: Thu Feb 14, 2013 2:22 am
Location: Jávea, Spain

Re: How to download code to Raspberry Pi to execute at start

Tue Jul 25, 2017 3:49 pm

If you wish to run automatically CLI commands or scripts (bash, python, etc) at startup, crontab should work fine.

I do not understand your comment related to compile and make.

When you compile a program, you generate an executable program which is ready to run. You will not need to recompile it again except if you have modified its source code.

So, you have no need to recompile a program after a reboot or something like that. Simply you have to call the executable file previously generated. If you use crontab -e, add a line like this:

Code: Select all

@reboot /my_path/my_exec_file_or_script opt_parms_here

gkaiseril
Posts: 679
Joined: Mon Aug 08, 2016 9:27 pm
Location: Chicago, IL

Re: How to download code to Raspberry Pi to execute at start

Tue Jul 25, 2017 5:59 pm

You need to make sure the script file you are trying to run has "execute" permission.

You can add that permission y using the chmod command

chmod +x myScriptFileName

Replace "myScriptFileName" with the file name of the bash script or other script you are trying to execute.
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.

miaomiao
Posts: 22
Joined: Fri Jun 30, 2017 4:07 am

Re: How to download code to Raspberry Pi to execute at start

Wed Jul 26, 2017 10:23 am

lmarmisa wrote:
Tue Jul 25, 2017 3:49 pm
If you wish to run automatically CLI commands or scripts (bash, python, etc) at startup, crontab should work fine.

I do not understand your comment related to compile and make.

When you compile a program, you generate an executable program which is ready to run. You will not need to recompile it again except if you have modified its source code.

So, you have no need to recompile a program after a reboot or something like that. Simply you have to call the executable file previously generated. If you use crontab -e, add a line like this:

Code: Select all

@reboot /my_path/my_exec_file_or_script opt_parms_here
Hi, I have tried so many times.still could not make it. I am using a laser scanner with Raspberry Pi2. It could work perfectly until I set to auto run at startup. It would hang there.

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: How to download code to Raspberry Pi to execute at start

Wed Jul 26, 2017 10:26 am

how do you start it when you are running normally ?
i.e.
what command do you type from where ?
what do you click
what do you need to do to get it to run now?
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

miaomiao
Posts: 22
Joined: Fri Jun 30, 2017 4:07 am

Re: How to download code to Raspberry Pi to execute at start

Wed Jul 26, 2017 10:37 am

RaTTuS wrote:
Wed Jul 26, 2017 10:26 am
how do you start it when you are running normally ?
i.e.
what command do you type from where ?
what do you click
what do you need to do to get it to run now?
I ran it normally by pi@raspberrypi: sudo ./get_distance
Now I am trying to auto run it when power on by pi@raspberrypi: sudo nano /etc/rc.local then key in my path

But it will hang somewhere,could not execute the program.

jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: How to download code to Raspberry Pi to execute at start

Wed Jul 26, 2017 11:02 am

miaomiao wrote:
Wed Jul 26, 2017 10:37 am
RaTTuS wrote:
Wed Jul 26, 2017 10:26 am
how do you start it when you are running normally ?
i.e.
what command do you type from where ?
what do you click
what do you need to do to get it to run now?
I ran it normally by pi@raspberrypi: sudo ./get_distance
Now I am trying to auto run it when power on by pi@raspberrypi: sudo nano /etc/rc.local then key in my path

But it will hang somewhere,could not execute the program.
When a program is run from rc.local it runs as root, so sudo is not required.
I would add some trace into the program (to a file) and see whats going on.

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: How to download code to Raspberry Pi to execute at start

Wed Jul 26, 2017 11:11 am

easiest for you would be get your rpi to auto log on to a commanline session and edit
.bashrc and put

Code: Select all

if [ $(tty) == /dev/tty1 ]; then
   sudo ./get_distance
fi
at the end,
if your program does not need keyboard input or display then I'd stuff it at the end of rc.local &
however
personally I'd run a systemd service and stuff it on a spare virtual terminal like viewtopic.php?f=29&t=7192&start=25#p898424 sor of thing [I do need to edit those instructions as I understand systemd a lot more now then when I wrote them [they should work though]
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Return to “General discussion”