How to execute a local script via html/js [closed]

I’m trying to create a web page with 2 buttons, ON/OFF.

When a button is pressed, a local script located on my file system on Ubuntu should run, like a C compiled program. How can I do this via HTML/JavaScript?

For a better understanding, when the button ON is pressed, ECHO 1 > /sys/class/led/leds/beaglebone:green/usr0 should run. This file is on the localhost that is hosting the page on the local LAN via Apache2, I’m trying just to run a printf before but I couldn’t yet.

When the button ON is pressed, ECHO 1 > /sys/class/led/leds/beaglebone:green/usr0 should run. This file is on the localhost that is hosting the page on the local LAN via Apache2, I’m trying just to run a printf before but I couldn’t yet.

  • 3

    You can’t execute local commands directly from JavaScript. What you need to do is register a handler for a URI scheme that runs the program, then follow a link that uses that URL. That’s how things like Zoom links work. For security reasons, the user has to authorize this.

    – 




  • You can use a JavaScript runtime environment like Node.js or Deno, PHP or CGI. There are many other options, but you asked for JavaScript and you are using Apache.

    – 




  • What you can also if you run your page on an Apache localhost is to send an Ajax call to a PHP script that can make a system call. For obvious reasons be careful that the script only do a pre-defined system call, I wouldn’t inject a user input in there personnally. And I prefer to do it when my localhost is isolated from the web

    – 




Leave a Comment