【发布时间】:2013-03-05 11:10:53
【问题描述】:
我正在编写 php 脚本,它将用于从“标准”站点创建站点。 unix shell命令很多,我发现了显示错误的问题。
示例:我需要检查站点文件夹是否不存在。
$ls_newsite = exec('ls /vhosts/'.$sitename, $output, $error_code);
if ($error_code == 0) {
Shell::error('This site already exists in /vhosts/');
}
Shell::output(sprintf("%'.-37s",$sitename).'OK!');
所以,我可以处理错误,但它还是会显示出来。
php shell.php testing.com
Checking site...
ls: cannot access /vhosts/testing.com: No such file or directory
testing.com.................................OK!
如何防止显示?谢谢
【问题讨论】:
-
正如@Colin Morelli 所说,您不需要为此使用控制台命令。
file_exists就足够了。 -
这只是显示问题的示例。
-
但即便如此,您应该使用
exec命令的情况并不多。
标签: php shell unix exec command-line-interface