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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html><head><title>Attempt to run an executable from a web page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
  <body>
    <a href=file://C:/HelloWorld.exe>Run Hello World Executable</a>
  </body>
</html>

and:
C:\HelloWorld.exe

// Filename        : HelloWorld.cpp
// Executable Name : HelloWorld.exe
#include <fstream>
using namespace std;

int main (int argc, char* argv[])
{
    ofstream outs;
    outs.open ("HelloWorld.txt");
    outs << "Hello World" << endl;
    return 0;
}

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.

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 ):

// Filename        : HelloWorld.cpp
// Executable Name : HelloWorld.exe
#include <fstream>
#include <iostream>
using namespace std;
 
int main (int argc, char* argv[])
{
    cout << "Content-Type:text/html;charset=iso-8859-1\n\n";
    ofstream outs;
    outs.open ("HelloWorld.txt");
    outs << "Hello World" << endl;
    return 0;
}

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 ).

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.