hm... I don't think its a fork problem, since window really create a child for the writing thread to the file, its just that the parent thread cannot read it until its child is finish. I think its more or less a flushing problem? Do you agree?
Anyways, I now have the following code, and IE give me a page not found error, do you know why?
#!D:/Perl/bin/Perl.exe -w
use strict;
use CGI ":standard";
use IO::Handle;
use Win32::Process;
use Win32;
$| = 1;
my $MYFILE = "D:\\tmp";
my $share = "begin";
if (param("monitor")) {
&monitor();
} else {
Win32::Process::Create($Process, "D:\\ping.exe yahoo.com >
+ ${MYFILE}",
"ping",0,DETACHED_PROCESS, ".") ||
+die "Create: $!";
}
#
print redirect(-uri => url() . "?monitor=yes", -nph=>1);
}
sub monitor
{
my $html = &draw_page();
if (defined $html) {
print header(-refresh=>1, -nph=>1), $html;
} else {
print header(-nph=>1), &goodbye();
}
}
sub goodbye
{
return start_html(-title=>"Goodbye!") . h1("Goodbye!") . end_h
+tml();
}
sub get_number
{
open NUMBER, "<$MYFILE" or return undef;
NUMBER->autoflush(1);
my $number = <NUMBER>; close NUMBER;
return $number;
}
sub draw_page
{
my $number = &get_number();
return (defined $number) ? start_html(-title=>"Your Lucky Numb
+er") . p("Your lucky number is $number.") . end_html() : undef;
}
sub do_stuff
{
for my $i (1 .. 10)
{
open NUMBER, ">$MYFILE";
NUMBER->autoflush(1);
print NUMBER "$i\n";
close NUMBER;
sleep 1;
}
unlink $MYFILE;
}
|