I want to make a local HTML page that will run in the browser locally (through file:///home/thierry/dev/index.html
).
This page will have a button, that, when pressed, will execute a shell script located on my local file system next to the HTML page.
I have tried with <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?
CodePudding user response:
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.)
CodePudding user response:
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!