2

使用 popen 或 proc_open 运行以下命令以列出 windows 共享的内容时:

smbclient -N  -U 'username%password' -O 'TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192'  -O 'TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192' -d 0 '//server/sharename' -c 'dir "dirpath\*"' 2>/dev/null

如果共享中的文件在遇到特殊字符时具有 § 字符(ASCII 21 十进制),则会跳过数据直到下一行。

        $descriptorspec = array(
        0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
        1 => array("pipe", "wb"),  // stdout is a pipe that the child will write to
        2 => array("pipe", "w") // stderr is a file to write to
    );

    $process = proc_open("smbclient -N  -U 'username%password' -O 'TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192'  -O 'TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192' -d 0 '//server/sharename' -c 'dir \"dirpath\*\"' 2>/dev/null", $descriptorspec, $pipes, null, null, array('binary_pipes'=>true));
    if(!is_resource($process)) {
        return false;
    }

    echo 'START[['.fread($pipes[1], 10096).']]END';
    fclose($pipes[0]);
    fclose($pipes[1]);
    fclose($pipes[2]);
    proc_close ($process); 

预期输出:

  .                                   D        0  Fri Feb  5 15:31:11 2010
  ..                                  D        0  Fri Feb  5 15:31:11 2010
  Test File § hello.doc              A   233472  Wed Feb  3 15:16:26 2010
  test.xls                                 11776  Tue Feb 24 11:14:28 2009

实际输出:

  .                                   D        0  Fri Feb  5 15:31:11 2010
  ..                                  D        0  Fri Feb  5 15:31:11 2010
  Test File   test.xls                                 11776  Tue Feb 24 11:14:28 2009
4

1 回答 1

2

shell 的 LANG 环境变量未设置为 unicode。

putenv('LANG=en_GB.UTF-8');

或者

setlocale(LC_CTYPE, "UTF8", "en_GB.UTF-8");

于 2010-02-12T16:29:06.007 回答