PHP shell_exec()导致txt文件?

I'd like to try to see the output of two shell_exec() calls in a .txt file.So i tried this:

$data_server = shell_exec('./c5.0demo -f $username -r');
$errorFile = "error.txt";
$fileopen = fopen($errorfile, 'w') or die ("can't open file");
fwrite($fileopen, $data_server);

$data_server2 = shell_exec('./predictBatch -f $username -r > $username.result');
$fileopen = fopen($errorfile, 'w') or die ("can't open file");
fwrite($fileopen, $data_server2);

The executable "c5.0demo" and "predictBatch" are in the same directory of this PHP's script. The variable $username is retrieved by POST method: $user = $_POST['username']; Being an array i put the value inside another variable by this:

 foreach($user as $val)
 $username .= $val;

I think this is correct but i don't have "error.txt" inside my directory. Why am i wrong? Thanks for all your support!

Try the following:

$data_server = shell_exec("./c5.0demo -f $username -r");
$data_server2 = shell_exec("./predictBatch -f $username -r > $username.result");

file_put_contents("/path/to/log/error.txt","{$data_server} : {$data_server2}
",FILE_APPEND);

Obviously $username needs to be defined - also, what is the datatype of $username? I ask, because $username.result looks very wrong.

You should also take very serious note of @mobius warning.