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

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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?
It simply flickers a light for now on testing
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.)
And what happens if you SSH onto your Pi and run sudo python /home/pi/Light.py?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.