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条)

报告相同问题?

悬赏问题

  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面