dozabg1616 2011-09-30 15:31
浏览 85

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!

  • 写回答

1条回答 默认 最新

  • dongma7725 2011-12-12 14:50
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入