Execute local sh-script from local HTML page

Viewed 58

I want to make and run a local HTML page (through file:///pathToFile/index.html).

This page will have a button. When pressed, a shell script located on my local file system next to the HTML page will be executed.

I tried: <input type="button" value="Test" onclick="window.open('./test.sh')" />

But the browser offers me to download the shell script instead of executing it.

How can I make the webpage execute a script locally, and get the result of the execution in a variable?

2 Answers

You cannot do that! Intentionally! Web page runs in its own sandbox and is not able to interact with your system bellow. Otherwise everyone could run anything on your machine (infect your system, delete files, etc.)

With plain JS it is not possible. You can exectute script from the server side (which would be your machine) with php. Using the shell_exec()-command.

Do note that you need to install/start a webserver with php locally!

Related