在我的cpp文件中,我正在打印一些debugging消息到std :: cout标准输出stream。 当我使用这个文件并运行使用Apache服务器的可执行文件。 debugging信息在哪里打印。 我没有看到它们打印在/ var / lib / httpd / error_log中。
提前致谢。
您应该使用Apache Web服务器来运行C ++程序的唯一原因是如果您制作CGI脚本
检查出来: http : //en.wikipedia.org/wiki/Common_Gateway_Interface
这里的过程是,Apache服务器运行你的程序,并使用输出(std :: cout)作为页面源。
页面源可以是html或纯文本。 唯一的问题是服务器不知道,所以你在输出开始时提供一点提示。 这就是所谓的标题。
如果你输出html,你必须打印:
内容类型:text / html
其次是两个换行符。
或者如果您希望Web服务器将数据解释为纯文本,则必须首先进行打印
内容类型:text / plain
之后还有两条换行符。
例如,一个应该工作的C ++程序看起来像这样:
#include <iostream> int main() { //output header, then one newline, then another, paired with a flush. std::cout << "Content-type: text/plain\n" << std::endl; //now your output //calculation... std::cout << "Hello World" << std::endl; return 0; }
任何Web服务器参数都可以用一些预设的环境变量来查询。 阅读我链接的维基百科文章。
编辑:
我很抱歉, Content-type: text/html
和Content-type: text/plain
是正确的,但我之前说过他们需要一个新的行。 我错了,他们需要两个新的线
如果这是你第一次看到这个帖子,不用担心。