列出.bat文件的共享文件夹

时间:2017-07-12 09:31:55

标签: php batch-file

我正在尝试在php中列出一个以这种方式执行.bat文件的共享文件夹

<?php
    header("Content-Type: text/html; charset=utf-8");
    $current_directory = getcwd();
    $command = "cmd /C $current_directory\\script.bat";
    $files = exec($command);
    var_dump($files);
?>

和bat文件

net use \\myurl\resources /user:Admin pass
dir \\myurl\resources\50000\Documents\myfolder >> log.txt

但我得到的响应是一个字符串,其中包含bat文件的最后一行,我如何获取文件夹内容列表?

1 个答案:

答案 0 :(得分:0)

这不是最漂亮的解决方案,但您可以使用passthruoutput buffering来解决此问题

<?php
header("Content-Type: text/html; charset=utf-8");
$current_directory = getcwd();
$command = "cmd /C $current_directory\\script.bat";

ob_start(); // Start the output buffer
passthru($command); // Execute the command
$files = ob_get_contents(); // Fetch the buffered output
ob_end_clean(); // Stop output buffering

var_dump($files);
?>
相关问题