我有一个启动我的exe的php文件。 exe执行cout并且文本以html格式打印,这一切都很好。直到我写“someline \ n”; \ n打破输出,我只看到最后一行。如何打印/回显其中包含多行的文本/字符串?

当前粘贴已经注释掉,我的文字打印正常。它在控制台看起来很丑陋,当我用IE7查看源码时(虽然我主要用FF浏览),看起来很痛苦。这是我目前的php和cpp文件

<html>
<head>
</head>
<body>
<?php
echo( exec('c:/path/to/exe/launchMe.exe hey lol hi') );
?>
</body>
</html>

CPP

#include <string>
#include <iostream>
#include <sstream>
using namespace std;

const string htmlLine(string s)
{
    s+= "<br />";
//  s += "\n";
    return s;
}

int main(int argc, char *argv[])
{
    stringstream s;
    s << argc;
    cout << htmlLine("woot") << htmlLine(s.str());
    for (int i=0; i<argc; ++i)
    {
        s.str("");
        s << i << " = " << argv[i];
        cout << htmlLine(s.str());
    }
    return 0;
}
有帮助吗?

解决方案

来自 http://php.net/exec

  

返回值

     

命令结果的最后一行。如果您需要执行命令并将命令中的所有数据直接传回而不受任何干扰,请使用 passthru()功能。

exec()函数仅返回输出的最后一行,但 passthru()返回所有输出。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top