Author Topic: how to run program from html page  (Read 2855 times)

0 Members and 1 Guest are viewing this topic.

Offline abdullahsebaTopic starter

  • Frequent Contributor
  • **
  • Posts: 335
  • Country: gb
how to run program from html page
« on: May 11, 2016, 10:17:27 am »
Hi
How 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 port
I 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.
This is my right hand this is my wrong hand
 

Offline ludzinc

  • Supporter
  • ****
  • Posts: 506
  • Country: au
    • My Misadventures In Engineering
Re: how to run program from html page
« Reply #1 on: May 11, 2016, 10:51:19 am »
From here:

http://stackoverflow.com/questions/18980957/is-it-possible-to-run-an-exe-or-bat-file-on-onclick-in-html

The following code works only when the EXE is Present in the User's Machine.

<a href = "C:\folder_name\program.exe">
 

Offline limtte

  • Newbie
  • Posts: 9
  • Country: de
Re: how to run program from html page
« Reply #2 on: May 11, 2016, 03:46:08 pm »
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 at flask, which provides the basic webserver functionality.
A really basic example is given on the main page:

Code: [Select]
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

and you could just add functionality to your liking:

Code: [Select]
@app.route("/turnLightsOn"):
def lightsOn():
    # do hardware stuff
    return "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).
 
The following users thanked this post: abdullahseba

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1999
  • Country: us
    • netstuff
Re: how to run program from html page
« Reply #3 on: May 11, 2016, 04:26:46 pm »
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.


Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: 00
Re: how to run program from html page
« Reply #4 on: May 11, 2016, 05:29:55 pm »
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.
 

Offline limtte

  • Newbie
  • Posts: 9
  • Country: de
Re: how to run program from html page
« Reply #5 on: May 11, 2016, 06:05:47 pm »
that at-sign stuff still puzzles me.

Yeah, 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:
[spoiler]
Taken from here:

Code: [Select]
def p_decorate(func):
   def func_wrapper(name):
       return "<p>{0}</p>".format(func(name))
   return func_wrapper


def 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: [Select]
# [...]
@p_decorate
def 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 I guess. But please don't quote me on that.  ::)
[/spoiler]


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 :D) running a python-webserver that's so easy to modify. :)
 

Offline rfeecs

  • Frequent Contributor
  • **
  • Posts: 807
  • Country: us
Re: how to run program from html page
« Reply #6 on: May 11, 2016, 06:44:37 pm »
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.
 

Offline aurmer

  • Regular Contributor
  • *
  • Posts: 84
  • Country: us
  • Insert text here.
Re: how to run program from html page
« Reply #7 on: May 14, 2016, 04:59:21 am »
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.

Apache
http://httpd.apache.org/docs/current/howto/cgi.html
IIS
https://www.iis.net/configreference/system.webserver/cgi

These pages are complete with example code to pull ideas from. Happy coding =)
If I just asked the wrong question, shame on me for asking before I was ready for help. Please be kind and direct me to a resource which will teach me the question I SHOULD be asking. Thank you.
 
The following users thanked this post: abdullahseba

Offline mav_iqdirect

  • Contributor
  • Posts: 15
  • Country: us
Re: how to run program from html page
« Reply #8 on: May 14, 2016, 03:23:59 pm »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf