how to run program from html page - Page 1
Forum section: electronics / beginners

author: abdullahseba
author_rank: Frequent Contributor
timestamp: May 11, 2016, 10:17:27 am
content: HiHow can I make a HTML button run an exe file on the server?I am using IIS 8 on Windows 10 and I want the client (a smartphone) to display the webpage and when the user taps the button, the server executes an .exe or .bat file that will send commends over the server's COM port.The .exe file is a C# program that has access to the server's COM portI assume the button will have to run some sort of cgi script that will in turn run the .exe file.I know its a security risk but it does not matter in my case.Anyone know how to to do this?Thanks in advance.

author: ludzinc
author_rank: Unknown
timestamp: May 11, 2016, 10:51:19 am
content: From here:http://stackoverflow.com/questions/18980957/is-it-possible-to-run-an-exe-or-bat-file-on-onclick-in-htmlThe following code works only when the EXE is Present in the User's Machine.<a href = "C:\folder_name\program.exe">

author: limtte
author_rank: Newbie
timestamp: May 11, 2016, 03:46:08 pm
content: I guess running the exe from the user's machine is not an option, since it seems that you want to control some piece of hardware remotely. I had a similar problem not long ago -- and I ended up programming a simple python webserver and implemented all the hardware-access-stuff as reactions to specific GET-/POST-Requests.Works quite well, easy to implement and since you are not concerned by security issues...You may want to look atflask, which provides the basic webserver functionality.A really basic example is given on the main page:Code:from flask import Flaskapp = Flask(__name__)@app.route("/")def hello():return "Hello World!"if __name__ == "__main__":app.run()and you could just add functionality to your liking:Code:@app.route("/turnLightsOn"):def lightsOn():# do hardware stuffreturn "success!"Now all you need to do is start your executable from within the method (or, even better, implement the COM-port connection in python ^^) and setup a small webpage with a button pointing at "<server_address>/turnLightsOn" (or whatever you actually want to call that method).

author: linux-works
author_rank: Super Contributor
timestamp: May 11, 2016, 04:26:46 pm
content: that at-sign stuff still puzzles me. I had it explained to me more than once, and it still makes me wonder what really happens when that line of code is there.but I realize its 'how its done' these days and that's a really compact bit of code that does an aweful lot.

author: Aodhan145
author_rank: Frequent Contributor
timestamp: May 11, 2016, 05:29:55 pm
content: Just use PHP it is in every basic LAMP installation and it is very simple to implement. If you google it there will be thousands of examples as PHP is the most used web language after Javascript.

author: limtte
author_rank: Newbie
timestamp: May 11, 2016, 06:05:47 pm
content: Quote from: linux-works on May 11, 2016, 04:26:46 pmYeah, I'm not really used to the @-sign as well, just using it. ;-)As far as I understand, those decorators return a function that replace the one you wrote and thus can modify and add more functionality to it.More:Taken fromhere:Code:def p_decorate(func):def func_wrapper(name):return "<p>{0}</p>".format(func(name))return func_wrapperdef get_text(name):return "lorem ipsum, {0} dolor sit amet".format(name)my_get_text = p_decorate(get_text)print my_get_text("John") # Outputs <p>lorem ipsum, John dolor sit amet</p>is just the complicated way of saying:Code:# [...]@p_decoratedef get_text(name):return "lorem ipsum, {0} dolor sit amet".format(name)print get_text( 'John' )Notice how p_decorate does not replace get_text with itself, but returns a function 'func_wrapper' that does so. It could do more that just returning a function, e.g. register the route for the webserver Iguess. But please don't quote me on that.BTT:Noticing that you are using Win10 and I've no clue what "IIS 8" does, yes, you may be better off with what Aodhan145 said. Getting python to run on windows and so on might not be worth the hassle, given that you already have the tools you need (which I don't know, but am just guessing).Still, nothing beats the feeling of a headless raspberry pi 1 (yes, the old 700 mhz one) running a python-webserver that's so easy to modify.

author: rfeecs
author_rank: Frequent Contributor
timestamp: May 11, 2016, 06:44:37 pm
content: Since you are using IIS and C# and Windows, I'm guessing that using ASP.NET would be the Microsoft way of doing things.You might want to search for "asp running an exe from web page" or something like that.

author: aurmer
author_rank: Regular Contributor
timestamp: May 14, 2016, 04:59:21 am
content: You were right about cgi scripts being the easiest solution.Here, you will find concepts in how CGI works.You can even have your C# program return values/data back to your IIS thread so it can be placed on the web interface... if that is something you would want.Apachehttp://httpd.apache.org/docs/current/howto/cgi.htmlIIShttps://www.iis.net/configreference/system.webserver/cgiThese pages are complete with example code to pull ideas from. Happy coding =)

author: mav_iqdirect
author_rank: Contributor
timestamp: May 14, 2016, 03:23:59 pm
content: I suggest you try ASP.NET MVC library to do this kind of stuff. Old ASP.NET is a little old. Anyway both technologies relate to C# programming.