CGI TASK

CGI TASK

HOW TO RUN C++ PROGRAM ON WEB BROWSER THROUGH CGI

There are two methods to do it.

  1. Without a script.
  2. 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.

29

Here, I have made two files

  1. “new.cpp”.
  2. “new”.

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

44.png

And you will get the output of c++ program  on browser.

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s