Running a simple C++ program combined with a web interface

Dear All,

I have some C++ code I would like to run on a web server. The C++ code itself is attached in a CodeBlocks project. To run it - add your directory path on line 13 of main.cpp

It does the following:
- Reads a file called INPUT.csv with some input data
- Reads a file called SETTINGS.csv with some settings set by the user (2 values - parameter A and parameter B)
- Performs calculations on data from INPUT.csv using values from SETTINGS.csv
- Outputs the result and saves it as OUTPUT.csv


I would like to adapt the code to run on a website:
- A web form which allows user to input values for A and for B
- A web form which promps the user to upload the source for processing_func_1.cpp - i.e. the user can modify it on his PC and upload a different version
- These values are then fed into the C++ module to perform calculations - the same as in standalone version - but with whatever processing_func_1cpp user has uploaded. values for INPUT.csv feed in from a file saved on the web server
- The program creates an OUTPUT.csv file which prompts user to either open or save it


The above is a sketch of the general principle behind the program - the actual code is massive (hence using C++ in the first place because computational speed is important). I have read about the following methods:

- Use CGI
- Boost Asio
- CppCMS

My question: what is the best way to go about adopting such code to take inputs from a web form and run on a web server?

Thank you
Erix
Normally you would create a website in html with the input form. Once the user filled out and submitted the form your code will process the input and send the output in html back to the browser.
However first you should check if the host allows to execute a c++ program on their server - unless you have your own server.

- A web form which promps the user to upload the source for processing_func_1.cpp - i.e. the user can modify it on his PC and upload a different version

I am not sure if this is possible at all. Normally c++ code needs to be compiled before it can be executed. You need to find a way to compile processing_func_1.cpp on the server and execute it.
Figures it out - it is certainly possible - a web server normally supports gcc compilation - fire up Apache and it should be possible to give command line arguments to compile stuff in gcc

There are a couple of ways of doing it:
- use a combo of CGI and Python to modify the program to take command line arguments - the user-input file is added to the input argument list -- the program compiles into an exe on the server and runs

- via a system() call in Php (my preferred method) -- this requires minimal modification to the code except changing the main to take argc argv

Topic archived. No new replies allowed.