5

I have made a little python program that lights up some LEDs to display the current heat of the pi, but I want to run it while I'm doing other stuff. I don't want it to run in a window because I often use command line. Is there a way of making doing this and how?

Using rasbian.

Matthew
  • 979
  • 3
  • 10
  • 20
  • How would you want to display the temperature, if the process is running in the background? – Gerben Aug 03 '13 at 20:05
  • Press ctrl+z and then run bg. Now the process is running in the background, but output is still printed to the current console window!!! – Gerben Aug 03 '13 at 20:07
  • It displays the approximate temperature using a BerryClip board which has 6 LED's. When the temperature is below 35 degrees 1 LED will turn on. When between 35 and 40 there will be 2 LED's turned on. When between 40 and 45... etc. – Matthew Aug 05 '13 at 09:45

2 Answers2

4

Assumptions: you are running Rasbian

You have a couple different options. For testing, you can run nohup ./python_script.py &. That uses a program called nohup to redirect all console output to a file, and then give you back your terminal.

Long term, you will probably want to start the program with cron and run it on reboot, so if the power goes out out your program will start as soon as it boots back up.

Cron is a little more advanced and requires a little more thought to setup. You have options as far as running a program at a certain time. For your application, it sounds like you can do something as simple as

$ crontab -e

and add the line:

@reboot /home/vivek/bin/python_script.py

Save and close, and then run

# update-rc.d cron defaults
Butters
  • 1,587
  • 8
  • 23
0

A quite messy way of doing this is to first start the .py in the command line before starting LXDE, then use Ctrl-Z. Type "bg && startx". The .py will run in the command line while LXDE can be used.
Credit to Gerben for the "Ctrl-Z" and "bg" idea.

Matthew
  • 979
  • 3
  • 10
  • 20