duanduan1993 2011-10-22 10:59
浏览 44
已采纳

PHP exec拆分命令在linux服务器上

I have a linux server running ubuntu 10.10 maverick with apache and php installed, in the /var/www directory I have a download directory. I have used OSFile manager and modified to include a function to split files here is the code:

function spl($fname){
 global $folder;
 if (!$fname == ""){
    maintop("Split");
    $dirfile = $folder.$fname;

    \\escape directory path
    $dirfile = str_replace(" ","\ ",$dirfile);
    $dirfile = str_replace("(","\(",$dirfile);
    $dirfile = str_replace(")","\)",$dirfile);
    $command = "split -d -b1024m ".$dirfile." ".$fname."_";
    echo "Command: ".$command;
    echo"<br />";


    $returnval =0;
    unset($output2);
    $output = exec($command,$output2,$returnval);

    //echo results
    echo($output);
    echo"<br />";
    print_r($output2);
    echo"<br />";
    echo($returnval);
    echo"<br />";
    mainbottom();
 }
  else
    home();
}

The command does not execute. The file and directory is correct but it returns exit code 1, and Array() as the output values, I have created a group that includes a few users, I have made this group the owner of downloads/ and given it read write and execute permissions, this group includes www-data.

Any Help will be apreciated

  • 写回答

2条回答 默认 最新

  • dongwuli5105 2011-10-22 12:00
    关注

    IF you don't get any error messages from exec and the error.log stays empty, then use this wrapper for executation:

     exec("sh -c \" $cmd 2>&1 \"");
    

    The 2>&1 redirects the stderr channel to stdout, so that it shows up in the result array.
    In the shell, what does " 2>&1 " mean?

    Another option would be proc_open where you can read each channel separately, but is more work to set up.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因