我有dir函数,用于查找所有可执行文件和目录,其代码如下:
$EXEC = 'X';
$DIR = 'D';
$FILE = 'F';
// depend on GNU version of find (not tested on different versions)
$cmd = "find . -mindepth 1 -maxdepth 1 \\( -type f -executable -printf ".
"'$EXEC%p\\0' \\) -o -type d -printf '$DIR%p\\0' -o \\( -type l -x".
"type d -printf '$DIR%p\\0' \\) -o -not -type d -printf '$FILE%p\\0'";
$result = $this->command($token, $cmd, $path);
我的命令功能具有如下代码:
$pre .= ";export LC_ALL=en_US.UTF-8; export HOME='$home';cd '$path'; $aliases\n";
$post = ";echo -n \"$marker\";pwd";
$command = escapeshellarg($pre . $command . $post);
$command = $this->sudo($token, $username, '/bin/bash -c ' . $command . ' 2>&1');
$command = $this->unbuffer($token, $command);
$result = $this->$shell_fn($token, $command);
其中$ shell_fn是shell执行函数之一或使用curl进行的perl / python cgi调用。
通过在命令之前添加export LC_ALL = en_US.UTF-8,我已经解决了ls的问题,它现在显示具有诸如RobertGawliński之类的Unicode字符的内容,但是当我这样做echo ą
或尝试在目录RobertGawliński上调用dir时,它就会中断。echo ą
显示Ä并cd Robert Gawliński
显示错误
/bin/bash: line 2: cd: $'Robert GawliÅ\302\204ski/': No such file or directory
似乎shell命令的输入是由php语言环境处理的,因此:
$locale = 'en_US.UTF-8';
setlocale(LC_ALL, $locale);
putenv('LC_ALL='.$locale);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句