1

I'm trying to make my raspberry PI host a website for control of a system on my house but can't run server side Python

I've tried this in Javascript:

import { exec } from 'child_process';
exec("sudo python /home/pi/Light.py");

It's supposed to run Light.py server side because it contains GPIO instructions for the pi but the PI just sits there doing nothing

Paulie_D
  • 107,962
  • 13
  • 142
  • 161

1 Answers1

3

Javascript's exec() is not for running anything server side, Python or otherwise.

Probably the easiest way to achieve what you're looking for would be to use a simple Python web framework, such as Flask. You could expose a simple HTTP endpoint doing whatever you need doing, and hit that from Javascript.

brunns
  • 2,689
  • 1
  • 13
  • 24
  • How and where is this Javascript being run? `child_process` looks like a node thing, which would also run server side. How's it being triggered? What happens if you SSH onto your Pi and run `sudo python /home/pi/Light.py`? – brunns Apr 15 '19 at 14:00
  • It simply flickers a light for now on testing – Nathan Johnson Apr 15 '19 at 14:11
  • Sorry, I need to be more specific. This Javascript code - where does it run, on your Pi, or on a client machine? How is it triggered? (What it does is unimportant from the point of view of solving your problem.) – brunns Apr 15 '19 at 14:15
  • And what happens if you SSH onto your Pi and run `sudo python /home/pi/Light.py`? – brunns Apr 15 '19 at 14:16