in reply to Re^8: Asynchronous Processing a command execution
in thread Asynchronous Processing a command execution
Whether you have one or more print header statements in your code does not matter unless they are run. But if you feel that you don't get the appropriate help here, maybe invest more time into checking your code yourself.
You are not printing the header. You can see this by running your code on the command line instead of running it as a CGI:
Q:\>perl -w tmp.pl Global symbol "$l" requires explicit package name at tmp.pl line 3. BEGIN not safe after errors--compilation aborted at tmp.pl line 4. Q:\>perl -w tmp.pl [Fri Jul 4 14:15:13 2008] tmp.pl: Statement unlikely to be reached at + tmp.pl li ne 51. [Fri Jul 4 14:15:13 2008] tmp.pl: (Maybe you meant system() when + you said exec()?) <!-- warning: Statement unlikely to be reached at tmp.pl line 51. --> <!-- warning: (Maybe you meant system() when you said exec()?) --> <h1>Software error:</h1> <pre>Can't locate Cache/FileCache.pm in @INC (@INC contains: C:/Progra +mme/Perl/l ib C:/Programme/Perl/site/lib .) at tmp.pl line 70. </pre> <p> For help, please send mail to this site's webmaster, giving this error + message and the time and date of the error. </p> [Fri Jul 4 14:15:13 2008] tmp.pl: Can't locate Cache/FileCache.pm in +@INC (@INC contains: C:/Programme/Perl/lib C:/Programme/Perl/site/lib .) at tmp. +pl line 70 . Q:\>
This is with this slightly modified program:
#!/usr/bin/perl use strict; #$l++; use CGI qw(:all); # import shortcuts use Fcntl qw(:flock); # imports LOCK_EX, LOCK_SH, LOCK_NB use CGI::Carp qw(warningsToBrowser fatalsToBrowser); # For Debugging #use Net::SSH::Perl; use CGI qw(:all delete_all escapeHTML); #use Net::SSH::Perl::Constants qw( :msg ); my ($TITLE,$DeploySvr,$KIT,$ssh,$UNM,$Pass,$stdout,$stderr,$exit,$cmd, +$session,$cache,$data,$pid,$packet,); if (my $session = param('session')) { # returning to pick up session data $cache = get_cache_handle(); $data = $cache->get($session); unless ($data and ref $data eq "ARRAY") { # something is wrong exit 0; } print header; print start_html(-title => "Logging...",($data->[0] ? () + : (-head => ["<meta http-equiv=refresh content=5>"]))); print h1("Logging..."); print pre(escapeHTML($data->[1])); print p(i("... continuing ...")) unless $data->[0]; print end_html; } else { $session = get_session_id(); $cache = get_cache_handle(); $cache->set($session, [0, ""]); # no data yet $DeploySvr=param('DrpServer'); $KIT=param('TxtKit'); $UNM=param('username'); $Pass=param('password'); if ($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 o +n $DeploySvr="113.128.122.27"; unless (open F, "-|") { open STDERR, ">&=1"; exec "/usr/sbin/traceroute", $DeploySv +r; die "Cannot execute traceroute: $!"; } my $buf = ""; while (<F>) { $buf .= $_; $cache->set($session, [0, $buf]); } $cache->set($session, [1, $buf]); } else { die "Cannot fork: $!"; } } sub get_cache_handle { require Cache::FileCache; Cache::FileCache->new ({ namespace => 'LogOutput', 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().$$)); }
So, obviously, you don't test your program right and you don't put enough effort into your program to reduce it to a minimal case.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |