doubi5520 2016-08-02 15:03
浏览 36
已采纳

too long

I have tried to run a batch file using PHP:

$script = "\\\MAFINFWWWPV02\D$\WebContent\\engsys.corp.ftr.com\BatchFiles\CopyFiles.bat";
exec($script,$ReturnArray,$ReturnValue);
//shell_exec($script);
//system('cmd /c $script');
//system($script,$ReturnValue);

None of these work! I've tried

var_dump($ReturnValue); echo "<br>";
var_dump($ReturnArray); echo "<br>";

to try and see what is going on, but I get what appears to be normal output like this:

int(1)

array(0) { }

But the files that I'm trying to copy with my bat file, which works fine when run manually, don't get copied!

Edit additional question

Do the \ need to be escaped in the file address?

EDIT 2

Here's what I get from running icacls:

CopyFiles.bat NT AUTHORITY\IUSR:(I)(RX)

         NT AUTHORITY\SYSTEM:(I)(F)

         NT AUTHORITY\NETWORK:(I)(RX)

         CORP\ibb601:(I)(F)

         CORP\taw330:(I)(F)

         CORP\mmm976:(I)(F)

         BUILTIN\Administrators:(I)(F)

         BUILTIN\Users:(I)(RX,W)

I have full control and everybody else has at least read/execute.

EDIT 3

I have narrowed it down. It's not that the commands are not working it's that permission is denied to the files. Which I don't understand since everyone has write and read/execute access to the entire folder.

EDIT 4

I am running the commands from above trying to get it to work. I am using a function (var_export(my_exec("shell_exec($script)"));) to print what the errors are to my screen. I keep getting something like this:

'\'shell_exec\' is not recognized as an internal or external command, operable program or batch file.

I get a different one for each shell_exec, system, and exec. It just keeps saying that the command is not recognized. This is being executed on a Windows Server 2012 R2 Standard 64-bit. Is there something that I'm doing wrong with the commands?

Function that I'm using to print errors (I found it on another post):

function my_exec($cmd, $input='')
    {
        $proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes); 
        fwrite($pipes[0], $input);fclose($pipes[0]); 
        $stdout=stream_get_contents($pipes[1]);fclose($pipes[1]); 
        $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]); 
        $rtn=proc_close($proc); 
        return array('stdout'=>$stdout,'stderr'=>$stderr,'return'=>$rtn); 
    }
  • 写回答

3条回答 默认 最新

  • dongzexi5125 2016-09-27 17:36
    关注

    I finally got it to work. Here's what I ended up with:

    $script = chr(92) . chr(92) . 'MAFINFWWWPV02\D$\WebContent\engsys.corp.ftr.com\BatchFiles\CopyFiles.bat';
    if (!file_exists($script))
    {
        var_dump($script); echo " Script<br>";
        echo "Script doesn't exist!<br>";
        var_dump(!file_exists($script));
    }
    else
    {
        system('cmd /c ' . $script); echo " <br>";
    }
    

    Sometimes I still get the Script doesn't exist! message, but that is usually when I'm connected to the #1 server and not the #2 server. The .nat looks like this:

    echo off
    SET source2="\\MAFINFWWWPV02\engsys.corp.ftr.com"
    
    START /wait NET USE L: "\\MAFINFWWWPV01\engsys.corp.ftr.com" Password /user:UserName
    
    xcopy %source2% L: /E /Y /Q
    
    NET USE L: /DELETE
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd