![]() |
Problem printing array content with CGI
hi,
I have a script that calls another module to exec a script, gets the output back in a array, and prints out the content of the array using CGI. If I run the script at the command line, it prints everything from the array correctly. However, if I run it on the brower, the program runs but nothing from the array gets displayed on the page. I have struggled with it for a while, any insight would be greatly appreciated. my $line; my (@stdout, @stderr); # $program_name is another Perl script my $scr = '/user/ice/htdocs/' . $program_name; # command to be sent to another program to exec my @cmd = ($scr, '-mode', $Mode, '-U', 'xxx', '-P', 'xxx', '-App', $AppName); # send for exec and gets its STDOUT and STDERR back using # @stdout and @stderr my $rc = ForkAndReadStdoutStderr(\@stdout, \@stderr, @cmd); if ($rc < 0) { print $Cgi->p($ICE::Fork::ERROR) } if ($rc > 0) { print $Cgi->p("@cmd FAILED! stdout=@stdout;stderr=@stderr") } print header('text/plain'); foreach $line (@stdout) { print $line; } My temporary solution now is to send the output of the script that I system() to a file and use "print redirect()" to display the file. Thanks, SL |
Re: Problem printing array content with CGI
Hi,
If a CGI works from a command line but not when called by a web server then 95% of the time it's a problem with permissions. Check _all_ files including the data files. --- Shawn Simon L wrote: > hi, > > I have a script that calls another module > to exec a script, gets the output back in a array, > and prints out the content of the array using CGI. > If I run the script at the command line, it prints > everything from the array correctly. However, if > I run it on the brower, the program runs but nothing > from the array gets displayed on the page. I have > struggled with it for a while, any insight would be > greatly appreciated. > > my $line; > my (@stdout, @stderr); > > # $program_name is another Perl script > my $scr = '/user/ice/htdocs/' . $program_name; > > # command to be sent to another program to exec > > my @cmd = ($scr, '-mode', $Mode, '-U', 'xxx', '-P', 'xxx', '-App', $AppName); > > # send for exec and gets its STDOUT and STDERR back using > # @stdout and @stderr > > my $rc = ForkAndReadStdoutStderr(\@stdout, \@stderr, @cmd); > if ($rc < 0) > { print $Cgi->p($ICE::Fork::ERROR) } > if ($rc > 0) > { print $Cgi->p("@cmd FAILED! stdout=@stdout;stderr=@stderr") } > > print header('text/plain'); > > foreach $line (@stdout) > { > print $line; > } > > My temporary solution now is to send the output > of the script that I system() to a file and > use "print redirect()" to display the file. > > Thanks, > SL |
Re: Problem printing array content with CGI
Shawn Corey wrote:
> If a CGI works from a command line but not when called by a web > server then 95% of the time it's a problem with permissions. Relative paths is a rather common cause as well. > Check _all_ files including the data files. And ensure that they are called with full paths. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl |
Re: Problem printing array content with CGI
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2rj362F19gourU1@uni-berlin.de>...
> Shawn Corey wrote: > > If a CGI works from a command line but not when called by a web > > server then 95% of the time it's a problem with permissions. > > Relative paths is a rather common cause as well. > > > Check _all_ files including the data files. > > And ensure that they are called with full paths. Thanks for your responses. I used absolute path. I subsequently wrote the code below, this time, it involves no files but only a pipe declared before a fork, and still, it works at command line but display nothing on the browser. I am starting to think maybe I missed something very basic. Any idea? pipe(FROM_CHILD, TO_PARENT); $pid = fork; my $data=undef; if($pid) { # parent close(TO_PARENT); $data = <FROM_CHILD>; print header('text/plain'); print $data; my $id = wait(); print "id=$id\n"; } else { #child close(FROM_CHILD); print TO_PARENT "Hello, call from child\n"; exit(0); } Thanks, SL |
Re: Problem printing array content with CGI
Steve May <junk@blackwater-pacific.com> wrote in message news:<10l9rfrjbi1ln70@corp.supernews.com>...
> Simon L wrote: > > > Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2rj362F19gourU1@uni-berlin.de>... > > > >>Shawn Corey wrote: > >> > >>>If a CGI works from a command line but not when called by a web > >>>server then 95% of the time it's a problem with permissions. > >> > >>Relative paths is a rather common cause as well. > >> > >> > >>>Check _all_ files including the data files. > >> > >>And ensure that they are called with full paths. > > > > > > Thanks for your responses. I used absolute path. I subsequently > > wrote the code below, this time, it involves no files but only > > a pipe declared before a fork, and still, it works at command line > > but display nothing on the browser. I am starting to think > > maybe I missed something very basic. Any idea? > > > This really sounds more like a server issue. > > I believe I'd be looking at my error log for clues.... > > > \s Thank you all for your responses. It was indeed a server issue. We did not compile Perl/mod_perl with sfio for security reason and hence system(), exec, pipe calls will not send output to the browser. I switched to use backticks to launch Perl scripts and it seems to work fine. Cheers, SL |
| All times are GMT. The time now is 11:37 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.