Reputation: 43
I'm trying to use fork for the first time, so I can redirect the user's web browser and then keep processing. I looked up the code for using fork, but my child process doesn't execute (i.e., the file doesn't get created). What am I doing wrong?
#! /usr/bin/perl
if ($pid = fork) { }
else {
close STDOUT();
open(FILE,'>test.txt');
print FILE time;
close(FILE);
exit(0);
}
print "Location: http://mydomain.com/\n\n";
Upvotes: 0
Views: 199
Reputation: 118705
STDOUT()
makes Perl look for a function called STDOUT
, and not finding one, aborts your child process.
$ perl -we 'close STDOUT()'
Undefined subroutine &main::STDOUT called at -e line 1.
You just need to say
close(STDOUT);
or
close STDOUT;
Even if you can only test this program in a web browser, the error message should still show up in the server error log.
Upvotes: 5