开发者

Any way to display C++ on a webpage?

开发者 https://www.devze.com 2023-01-03 05:56 出处:网络
Is there a relatively easy way to display the output of a C++ program on a webpage? And I don\'t mean manually, in other words, you see it on a webpage as it runs not as in I make a code tag and write

Is there a relatively easy way to display the output of a C++ program on a webpage? And I don't mean manually, in other words, you see it on a webpage as it runs not as in I make a code tag and write it in myself.

EDIT: Just so everybody can get this clear I am going to post this up here. I am NOT try开发者_如何学Going to make a webpage in C++. Please excuse me if this sounds spiteful or anything but I am getting a lot of answers relating to that.


Step one, get yourself a server-side language. Be that PHP, ASP, Python, Ruby, whatever. Get it set up so you can serve it.

Step two, find your language's exec equivalent. Practically all of them have them. It'll let you run a command as if it were from the command line, usually with arguments and capture the output. Here's PHP's:

http://php.net/manual/en/function.exec.php

Of course, if you're passing user-input as arguments, sanitise!


I've just seen that you accepted Scott's answer. I usually wouldn't chase up a SO thread so persistently but I fear you're about to make a mistake that you'll come to regret down the line. Giving direct access to your program and its own built-in server is a terrible idea for two reasons:

  1. You waste a day implementing this built-in server and then getting it to persist and testing it

  2. More importantly, you've just opened up another attack vector into your server. When it comes to security, keep it simple.

You're far better having your C++ app running behind another (mature) server side language as all the work is done for you and it can filter the input to keep things safe.


You could write a CGI app in C++, or you could use an existing web server language to execute the command and send the output to the client.


You want to use Witty.

Wt (pronounced 'witty') is a C++ library for developing interactive web applications.

The API is widget-centric and similar to desktop GUI APIs. To the developer, it offers complete abstraction of any web-specific implementation details, including event handling, graphics support, graceful degradation (or progressive enhancement), and pretty URLs.

Unlike many page-based frameworks, Wt was designed for creating stateful applications that are at the same time highly interactive (leveraging techinques such as AJAX to their fullest) and accessible (supporting plain HTML browsers), using automatic graceful degradation or progressive enhancement.

The library comes with an application server that acts as a stand-alone web server or integrates through FastCGI with other web servers.


I am not sure this is what you are looking for but you may want CGI You may want to look at this SO question, C++ may not be the best language for what you want to do.

based off the questions you posted Writing a web app like what you want is no simple task. What I would recommend is use some other library (this is one i found with a quick google) to get a web console on your server and give the user it is running under execute deny permissions on every folder except the folder you have your app installed.

This is still is a risky method if you don't set up the security correctly but it is the easiest solution without digging around too much on existing libraries to just have the application interactive.

EDIT -- The "Best" solution is learn AJAX and have your program post its own pages with it but like I said, it will not be easy.


It sounds like you want something like a telnet session embedded in a webpage. A quick google turns up many Java telnet apps, though I'm not qualified to evaluate which would be most ideal to embed in html.

You would set up the login script on the host machine to run your c++ app and the user would interact with it through the shell window. Note though that this will only work for pure command line apps. If you want to use a GUI app in this way, then you should look into remote desktop software or VNC.


It may be worth looking into Adobe's "Alchemy" project on Adobe Labs

This may help you with what you're trying to achieve.

:)


Are you looking for something like what codepad.org does? I believe they explain how they did it here.


There is a library called C++ Server Pages - Poco. I used it for one of my college project, its pretty good. There is also good documentation to get started with, u can find it here http://pocoproject.org/docs/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号