看看这个函数的含义

shenjiangweizz 2009-05-23 02:04:15

$g = array(
"varrun_path" => "/var/run",
"varetc_path" => "/var/etc",
"vardb_path" => "/var/db",
"varlog_path" => "/var/log",
"etc_path" => "/etc",
"tmp_path" => "/tmp",
"conf_path" => "/conf",
"ftmp_path" => "/ftmp",
"conf_default_path" => "/conf.default",
"cf_path" => "/cf",
"cf_conf_path" => "/cf/conf",
"www_path" => "/usr/local/www",
"xml_rootobj" => "freenas",
"debug" => false,
"latest_config" => "5.7",
"nopccard_platforms" => array("wrap", "net48xx"),
"wireless_regex" => "/^(ndis|wi|ath|an|ral|ural|wai|iwi|awi|wlan|ipw)/",
"default_passwd" => "freenas",
"default_ip" => "192.168.1.250"
);

function mwexec($command, $logerr = false) {
global $g;

// Set PATH
putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");

if ($g['debug']) {
if (!$_SERVER['REMOTE_ADDR'])
echo "mwexec(): $command\n";
passthru($command, $retval);
} else {
$redirect = ">/dev/null 2>&1";

if (true === $logerr)
$redirect = "2>&1 >/dev/null";

exec("{$command} {$redirect}", $output, $retval);
if ((true === $logerr) && (is_array($output))) {
write_log(implode($output));
}
}

return $retval;
}

function mwexec2($command, &$output = NULL, &$return_var = NULL) {
// Set PATH
putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
return exec($command, $output, $return_var);
}

/* wrapper for exec() in background */
function mwexec_bg($command) {
global $g;

// Set PATH
putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");

if ($g['debug']) {
if (!$_SERVER['REMOTE_ADDR'])
echo "mwexec(): $command\n";
}

exec("nohup $command > /dev/null 2>&1 &");
}

/* unlink a file, if it exists */
function unlink_if_exists($fn) {
if (file_exists($fn))
unlink($fn);
}

哪位高手帮忙看下这几个函数到底有什么作用 有什么含义呀
...全文
81 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
程序猿之殇 2009-05-25
  • 打赏
  • 举报
回复
2>&1 表示“将标准错误发送至标准输出被重定向的任何位置”,因此错误和正常的消息都将在屏幕上显示
程序猿之殇 2009-05-25
  • 打赏
  • 举报
回复
2>/dev/null 出错的时候不写入日志.

1 2都是执行并且要求的到结果,第一个函数不需要得到执行的结果,将命令行返回的数据写入日志,函数本身返回,命令行执行的结果状态. 第二个函数,对exec的包装,将命令行返回的数据和执行的结果状态值以传值的方式返回.

3 让命令在后台运行.

testoktest 2009-05-23
  • 打赏
  • 举报
回复
不知道啊,看到>/dev/null 2>&1 好熟悉阿,不作任何输出运行一个命令
最后一个我知道,unlink_if_exists()是删除文件,嘿嘿
1,2,3都是执行一个linux命令
2的参数是引用,所以……
3,执行命令。如果debug了,之前还用php输出显示一下这个命令本身
1。执行命令。有时候写日志,有时不写,有时有默认输出,有时没有
这些加起来干什么呢,难不成是……
jim8590251 2009-05-23
  • 打赏
  • 举报
回复
不懂....

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧