User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the HTML and CSS section within the Web Development category of DaniWeb, a massive community of 391,667 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,927 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our HTML and CSS advertiser: Lunarpages Web Hosting
Views: 869 | Replies: 2
Reply
Join Date: Jan 2008
Posts: 1,403
Reputation: VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough 
Rep Power: 6
Solved Threads: 179
VernonDozier VernonDozier is offline Offline
Nearly a Posting Virtuoso

Trying to run a C++ program through a web link

  #1  
Mar 12th, 2008
This is my first shot at running an executable program from a web page. The program is going to get a lot bigger, as will the web site. I have xampp installed and I am using that. I have two simple files:


C:\xampp\htdocs\execlink.html
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html><head><title>Attempt to run an executable from a web page</title>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4.  
  5. </head>
  6. <body>
  7. <a href=file://C:/HelloWorld.exe>Run Hello World Executable</a>
  8. </body>
  9. </html>

and:
C:\HelloWorld.exe
  1. // Filename : HelloWorld.cpp
  2. // Executable Name : HelloWorld.exe
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. int main (int argc, char* argv[])
  7. {
  8. ofstream outs;
  9. outs.open ("HelloWorld.txt");
  10. outs << "Hello World" << endl;
  11. return 0;
  12. }
The web page is:
http://127.0.0.1/execlink.html

Anyway, I click on the link within execlink.html that is supposed to run HelloWorld.exe and nothing happens. The program doesn't run, which I suppose is probably a good thing from a security standpoint since I still have basically the default configuration. I have heard that I need to rename the executable file with a ".cgi" extension from a ".exe" extension and stick it somewhere besides the root "C" directory and maybe mess with a configuration file or two. Any ideas? Thank you.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Trying to run a C++ program through a web link

  #2  
Mar 13th, 2008
I'm not sure what configuration tricks you'll need to perform to get this to work on Windows + XAMPP, but, the following looks 'wrong':

- your href in the HTML goes to a local file, this certainly wont work. You'll need to move the compiled C++ application into the folder which XAMPP maps to 127.0.0.1, and change the link to href="http://127.0.0.1/HelloWorld.exe".
- It is possibly the case that the C++ app will have to go into the cgi-bin folder, I haven't used XAMPP for a long time, and cant remember how it deals with executables and permissions.. read the XAMPP docs if in doubt.
- The program will not work properly as a CGI script because it's not sending an HTTP header. Change to the following ( although the program should work [ as in write to the file ] if you set everything up properly, it will display an Error 500 if you do not make this change ):
  1. // Filename : HelloWorld.cpp
  2. // Executable Name : HelloWorld.exe
  3. #include <fstream>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int main (int argc, char* argv[])
  8. {
  9. cout << "Content-Type:text/html;charset=iso-8859-1\n\n";
  10. ofstream outs;
  11. outs.open ("HelloWorld.txt");
  12. outs << "Hello World" << endl;
  13. return 0;
  14. }

Don't worry about security right now ( but certainly read up about it when you get the time ). XAMPP doesn't make your computer a public server with the default settings, and nobody but you can access 127.0.0.1 and see your files, if I go to 127.0.0.1 it will send me to any server program on my PC ( I don't have one running, but it would if I had Apache on ).
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Jan 2008
Posts: 1,403
Reputation: VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough 
Rep Power: 6
Solved Threads: 179
VernonDozier VernonDozier is offline Offline
Nearly a Posting Virtuoso

Re: Trying to run a C++ program through a web link

  #3  
Mar 13th, 2008
Thank you for replying. I've been fiddling around with it. It seems to be looking in the current directory (as opposed to the cgi-bin directory). It finds HelloWorld.exe now, but doesn't seem to realize I am trying to execute it and it offers to let me save it. Seems like it thinks it is a text file or something. I changed the link to a perl file that came with xampp. It displayed (but did not run) that program to the screen, but still looked for the one in the local directory. When I switched to a link with a .cgi suffix, it appears to have looked in the cgi-bin directory and actually ran it. It was set up to print information in html and it did that. However, it didn't print the word "print" but rather the contents inside the quotes, so I'm guessing that one worked correctly. It seems like the suffix of the file is important as far as xampp knowing what to do with it? There must be a list of file extensions somewhere where I need to specify that I want".exe" to run? Still experimenting around with this. Thank you.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb HTML and CSS Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the HTML and CSS Forum

All times are GMT -4. The time now is 1:54 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC