【问题标题】:execute a whois unix command using system()使用 system() 执行 whois unix 命令
【发布时间】:2013-01-31 19:31:44
【问题描述】:

有没有办法/是否可以使用 php 执行 unix whois 查询,可能使用 system().?

我在努力

echo '<pre>';
$last_line = system('whois ryansmurphy.com', $retval);
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;

但它不起作用。我做错了什么?

什么也没看到,没有错误,没有输出。

【问题讨论】:

  • 应该可以,你的问题是什么?也许它不起作用,因为您使用的是反引号而不是引号?
  • @抱歉解释不善。查看更新
  • 什么不起作用?您看到什么输出/错误?你想做什么?
  • 检查$last_line 是否为假。如果是,则命令失败。
  • 运行passthru('whois ryansmurphy.com');有结果吗?

标签: php unix system whois


【解决方案1】:

使用

exec($command, $output, $exit_code);

地点:

$command - 你的命令(“whois ...”)

$output - 命令输出。

$exit_code - 命令退出代码

exec command PHP

【讨论】:

  • 不,不要使用 PHP 中的 exec 进行 whois 查询。
【解决方案2】:

如果命令没有返回任何内容,那么它很可能会将错误返回到标准错误,而该错误未被捕获。尝试添加 2&gt;&amp;1 以将错误发送到标准输出。

$last_line = system('whois ryansmurphy.com 2&gt;&amp;1', $retval);

这在 system()exec() 的 PHP 手册中有介绍

【讨论】:

  • 不,不要使用 PHP 中的 system 进行 whois 查询。
猜你喜欢
  • 1970-01-01
  • 2021-02-27
  • 1970-01-01
  • 1970-01-01
  • 2011-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多