Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Problem printing array content with CGI (http://www.velocityreviews.com/forums/t888179-problem-printing-array-content-with-cgi.html)

Simon L 09-24-2004 04:09 PM

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

Shawn Corey 09-24-2004 04:39 PM

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



Gunnar Hjalmarsson 09-24-2004 05:19 PM

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

Simon L 09-25-2004 03:08 AM

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

Simon L 09-30-2004 03:49 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57