views:

3094

answers:

2

i have a php file launching my exe. the exe does cout and the text is printed in html which is all fine. until i write "someline\n"; The \n breaks the output and i only see the last line. How do i print/echo text/strings that has multilines in them?

The current paste has \n commented out and my text prints fine. It looks ugly in the console and when i view source with IE7 (although i primarily browse with FF) the source is painful to look at. Here is my current php and cpp file

<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;
}
+5  A: 

From http://php.net/exec:

Return Values

The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.

The exec() function only returns the last line of ouput, but passthru() returns all output.

yjerem
A: 

sweet, thanks Jeremy, it works perfectly now

acidzombie24