-1

Firstly, I am aware that this question has been asked before (Is it possible to run an .exe or .bat file on 'onclick' in HTML) but I tried to do what was suggested and I could not make it work.

Here is my code:

<html>
<body>

<input type="button" value="Launch Installer" onclick="window.open(file:///S:downloads/thing.sh)” />

</body>
</html>

This code is in a file called "test.html" in my downloads folder.
I ran it in command line with this command

open test.html  

and that resulted in google chrome opening a blank page.

Also, I have an shell script in my downloads folder named "thing.sh" containing this code:

echo hello world

Thanks for the help.

Using PHP (I've tried fixing my file path and it still doesn't work)

I tried what was suggested in the link provided by james111 (how to run a .sh file from php?) and this is my code:

<?php
echo shell_exec(‘Users/mathewlewis/downloads/thing.sh');
?>

I'm not sure how to run a php file from command line like I did with the html file (I have this code saved in a file called test.php) so I tried putting it in a file named test.html and that created a blank page in chrome like before.

Community
  • 1
  • 1
Mathew
  • 1,116
  • 5
  • 27
  • 59
  • First, your slashes are wrong. Second: it's not supposed to work. You will download the file rather than run it. – GiantTree Jun 17 '16 at 07:17
  • Third, your file address in .open() should be wrapped around quotes. Although it will download the file :) – Priyesh Kumar Jun 17 '16 at 07:20
  • For this you use applets, or uise object tag. However it's very often a security breac which is why it's not recommanded. Finally, you want to run a .sh file in client browser, how can it executes against a WIndows user ? It just can't. If you want to have your user download/or execute a setup file with the usual toolbox (download/execute). Just make a classic href pointing to that file. – Walfrat Jun 17 '16 at 08:21

2 Answers2

1

You cannot run a file like this, plain and simple.

It'll just download the file, that's if your path was correct, which it isn't.

You may consider looking into a php alternative How to run abc.exe using php

Run sh files how to run a .sh file from php?

Edit:

You've tried to run a bash file using PHP, I'm assuming you're trying to run it from you Downloads folder?

Your path is incorrect, it should look something like this:

/Users/<user_name>/Downloads/thing.sh

But if you're running it from your server (in the folder of your php file), you'd reference the location based on the folder your php file is in.

Community
  • 1
  • 1
James111
  • 15,378
  • 15
  • 78
  • 121
  • Maybe not exactly like this, but there seems to be plenty of ways to launch an executable from the browser. A quick google search results in multiple questions and working answers around the topic in SO. It's not that plain and simple, especially if the file is already stored locally. – Roope Jun 17 '16 at 07:30
  • 1
    Yep, but the way the OP wants to do it you cannot. Which is why I've explicitly said that they cannot. @Roope – James111 Jun 17 '16 at 07:32
  • @james111 thanks for the link but I use a mac and it says it is only for windows. could you provide me with a mac method for running an executable in php or html. thanks – Mathew Jun 17 '16 at 08:07
  • @mathew I've added a link to my answer – James111 Jun 17 '16 at 08:09
  • I just edited the question explaining how I tried to do what your link suggested. – Mathew Jun 17 '16 at 08:54
  • @mathew - I've edited my answer...You must use the right file path. – James111 Jun 17 '16 at 09:02
  • I tried the new file path and that didn't work either. Also, like I mentioned in the edit, I don't know how to run a .php file so its in a .html file which I am running from command line using the command "open test.html" which is still creating a blank page. Just wondering if that is part of the problem. – Mathew Jun 17 '16 at 09:40
0

You can use URL Protocol to do the thing according to your requirement. try this method, Link to url Protocol sample