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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器