2011-09-21 69 views
1

谁能告诉我为什么firefox不打开与下面的Net :: HTTPServer线添加?

#!/usr/bin/perl 
# v5.10.1/linux 
use strict; 
use warnings; 
use Shell; 
use Net::HTTPServer; 


############ section ############### 
my $server = new Net::HTTPServer(
           port=>5000, 
           docroot=>"/home/frank/Perl/perl_info_pages", 
           log => "/home/frank/Perl/perl_info_pages/access.log", 

           chroot => 0,  #  - Run the server behind a virtual chroot(). 
           # Since only root can actually call chroot, 
           # a URL munger is provided that will not 
           # allow URLs to go beyond the document root 
           # if this is specified. 
           # (Default: 1)/true ??? 

           # allow only for localhost... and user *** 
           # super server daemon control of?? 
           # cgi... 
           ); 

$server->Start(); 
$server->Process(); 
############# end of section ################### 

# can anyone tell me why these lines work(to open up firefox) with the above section commented out, but do not work when they are uncommented?? 
my $linkurl = 'http://localhost:5000'; 
firefox ("$linkurl"); 
+0

取而代之的是什么?这是Perl脚本的最后一行吗?你是否定义了一个'firefox'函数? –

+0

是的最后一行是我的脚本的一部分。我认为“使用壳牌;”是它工作所需要的(我没有为它定义的函数)。 – Carpenter

回答

1

作为解释到的HttpServer文档中,Process()呼叫阻塞和无限期地运行服务器,因此最后两行从来没有达到过。

您可以做的最简单的事情是在StartProcess之间产生Firefox进程:套接字已经被创建,并且当进程派生代码将返回时服务器将开始运行。

+0

谢谢,这些意味着我必须分叉或线程服务器部分?对不起,我希望这是可以问的吗? – Carpenter

+0

可以这样做,或者简单地在'开始'之后创建Firefox进程。 –

1

Net::HTTPServerProcess方法永远不会返回,除非您给它超时。如果要打印消息,则必须在调用Process之前执行此操作。如果你想知道服务器绑定到什么端口,你可以在开始之后执行它。