How To Run A C++ Program On Web Browser Through CGI

There are two methods to do it.

  1. Without a script.
  2. With a script.

Now, there are two files named as 

 

  1. "new.cpp".
  2. "new".

 

Give permissions to both the files with

 

  1. "sudo chmod 777 new.cpp".
  2. "sudo chmod 777 new".

 

 

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.

 

4. Text within this element is typically displayed in a non-proportional font exactly it is laid out in a file.

 

5. Here "new.cpp" is the file with output filename "n". Whitespace inside this element is displayed as typed.

 

6.   The HTML </pre> is the closing element.

Finally, to get the output on Browser type the URL "localhost/cgi-bin/new".

deck

By amisha2016

deck

  • 444