Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I call this on the command line with - "perl new3.cgi" and I get -#!/usr/bin/perl -w use strict; $|++; $ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/ +sbin"; use CGI qw(:all delete_all escapeHTML); print header(), start_html(-title => "Traceroute Results"); print h1("Traceroute Results"); #open STDERR, ">&=1"; exec '/usr/bin/perl', '-T', 'child.pl', 'number=4' or die "Cannot exec +ute : $!"; print end_html;
Content-Type: text/html; charset=ISO-8859-1 <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"><head><title>Traceroute Results</title> </head><body><h1>Traceroute Results</h1>param: 4 Command line reporter Called with 1 parameters which was 1: number=4 * *
Notice "Param:" , theres no number passed but if I uncomment the line - open STDERR, ">&=1"; I get -Traceroute Results param: Command line reporter Called with 1 parameters which was 1: num ber=4 * *
The command line call is working fine, the browser calls are not So I'm guessing my problem has something to do with buffering. THe actual parent script I wish to call is a rework of the following -Traceroute Results Use of uninitialized value in concatenation (.) or string at child.pl +line 10. param: Command line reporter Called with 1 parameters which +was 1: number=4 * *
#!/usr/bin/perl -w use strict; $|++; $ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local +/sbin"; use CGI qw(:all delete_all escapeHTML); sub show_form { print header, start_html("Traceroute"), h1("Traceroute"); print start_form; print submit('traceroute to this host:'), " ", textfield('host'); print end_form, end_html; } sub get_cache_handle { require Cache::FileCache; Cache::FileCache->new ({ namespace => 'tracerouter', username => 'nobody', default_expires_in => '30 minutes', auto_purge_interval => '4 hours', }); } sub get_session_id { require Digest::MD5; Digest::MD5::md5_hex(Digest::MD5::md5_hex(time().{}.rand().$$)); } if (my $session = param('session')) { # returning to pick up session +data my $cache = get_cache_handle(); my $data = $cache->get($session); unless ($data and ref $data eq "ARRAY") { # something is wrong show_form(); exit 0; } print header(), start_html(-title => "Traceroute Results", ($data->[0] ? () : (-head => ["<meta http-equiv=refresh content=5>"]))); print h1("Traceroute Results"); print pre(escapeHTML($data->[1])); print p(i("... continuing ...")) unless $data->[0]; print end_html; } elsif (my $host = param('host')) { # returning to select host if ($host =~ /^([a-zA-Z0-9.\-]{1,100})\z/) { # create a session $host = $1; # untainted now my $session = get_session_id(); my $cache = get_cache_handle(); $cache->set($session, [0, ""]); # no data yet if (my $pid = fork) { # parent does delete_all(); # clear parameters param('session', $session); print redirect(self_url()); } elsif (defined $pid) { # child does close STDOUT; # so parent can go on unless (open F, "-|") { open STDERR, ">&=1"; exec '/usr/bin/perl', '-T', 'child.pl', 'number=4' or die "Cannot execute : $!"; } my $buf = ""; while (<F>) { $buf .= $_; $cache->set($session, [0, $buf]); } $cache->set($session, [1, $buf]); exit 0; } else { die "Cannot fork: $!"; } } else { show_form(); } } else { # display form show_form(); } exit 0;
20040828 Janitored by Corion - localized link
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing Args via Exec (2)
by Anonymous Monk on Aug 28, 2004 at 22:49 UTC |