I have got a C++ program that accepts a string and gives output as a string now what I need do is take the string input from the textbox on a webpage and then submit the result to a database?

Submitting to database is a later case but first tell me how can I do the first part??

Dani AI

Generated

asked how to take a textbox string from a webpage, hand it to a C++ program, and (later) save the returned string to a database. pointed out invoking the compiled program from the server — that is a valid path. Below are practical options, pitfalls to avoid, and a short checklist to move from prototype to production.

Common approaches (choose one)

  • Turn the C++ code into a small persistent service (HTTP/REST or a socket) so the web layer sends input and receives output over a request/response API. This avoids spawning a process per web request and is easier to scale. See cpp-httplib for a tiny single-header example.
  • Integrate via FastCGI/CGI when using a traditional web server (good for simple deployments; see the CGI spec).
  • For quick prototypes only: spawn the executable per request, but follow the safety checklist below.

Safety and robustness checklist (must-haves)

  • Never trust raw input. Validate and canonicalize before processing; follow OWASP guidance on preventing command injection: .
  • Use absolute paths, pass user data via stdin or securely-created temp files (avoid interpolating into a shell command), and capture stdout and stderr.
  • Enforce strict resource limits and timeouts (CPU, memory, wall-clock), run the process as an unprivileged user or inside a container, and log errors and exit codes.
  • Sanitize the program output before storing: check character encoding, strip unexpected control bytes, and then write to the database via parameterized/prepared statements (do not concatenate SQL).

Operational notes
If the C++ work is heavy or long-running, push tasks to a worker queue and have workers write results to the DB. That pattern separates web latency from processing and makes retries and monitoring straightforward.

Recommended Answers

All 2 Replies

Thanks a lot for your reply it really helped !!!!

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.