HOW TO RUN C++ PROGRAM ON WEB BROWSER THROUGH CGI
There are two methods to do it.
- Without a script.
- With a script.
As you can see, I have explained first method in detail in the previous blog.
Now, we will discuss the second method i.e. with a script.
Here, I have made two files
Both these files should be in the same directory “/usr/lib/cgi-bin”.
Give permissions to both the files with
“sudo chmod 777 new.cpp”.
“sudo chmod 777 new”.
Make sure all permissions are given to the folder and files.
The file with name “new” is a script file.
Here is the explanation of the code.
1. In the line “#!/bin/sh” #!(i.e. hash bang) means to include the shell “sh” to interpret the following code and execute the script. In place of “sh” we can write “bash”, “dash”. All these are shells to interpret the code.
2. The word “echo” is used to output status text to the screen or a file. It is used to get the feedback.
3. The HTML <pre> element (or HTML Preformatted Text) represents preformatted text. Text within this element is typically displayed in a non-proportional font exactly it is laid out in a file. Here “new.cpp” is the file with output filename “n”. Whitespace inside this element is displayed as typed.
4. The HTML </pre> is the closing element.
Now compile the c++ program through “sudo g++ new.cpp -o n”,where “n” is the output filename.
At web browser search the URL “localhost/cgi-bin/new”.
And you will get the output of c++ program on browser.