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.

  • How would you want to display the temperature, if the process is running in the background?
    – Gerben
    Aug 3, 2013 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 3, 2013 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 5, 2013 at 9:45

2 Answers 2


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
  • How do I run the file using cron?
    – Matthew
    Aug 3, 2013 at 15:41
  • @Matthew updated answer.
    – Butters
    Aug 3, 2013 at 15:51
  • I tried this but it doesn't work.
    – Matthew
    Aug 3, 2013 at 16:13
  • @Matthew It should be enough to get you in the right direction though. Look at this post on server fault for more info on cron and some troubleshooting assistance.
    – Butters
    Aug 3, 2013 at 18:55

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.

  • On a more mature SE site I would downvote this. There is not reason for such a messy workaround. See Butters' excellent answer.
    – dotancohen
    Aug 5, 2013 at 11:05
  • @dotancohen I did try Butter's answer but it didn't work for me. This is just another option, although not the best.
    – Matthew
    Aug 5, 2013 at 11:34
  • Then troubleshoot why it didn't work.
    – dotancohen
    Aug 5, 2013 at 12:04
  • Can't be bothered; this works fine for me and is much simpler to setup then cron.
    – Matthew
    Jul 9, 2014 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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