Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Problem printing array content with CGI

Reply
Thread Tools

Problem printing array content with CGI

 
 
Simon L
Guest
Posts: n/a
 
      09-24-2004
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
 
Reply With Quote
 
 
 
 
Shawn Corey
Guest
Posts: n/a
 
      09-24-2004
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


 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-24-2004
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
 
Reply With Quote
 
Simon L
Guest
Posts: n/a
 
      09-25-2004
Gunnar Hjalmarsson <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
 
Reply With Quote
 
Simon L
Guest
Posts: n/a
 
      09-30-2004
Steve May <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Simon L wrote:
>
> > Gunnar Hjalmarsson <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> >
> >>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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 PM
Problem while printing the content of an array, which is pointed bya variable Victor Reyes Ruby 2 04-07-2008 12:43 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:50 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:28 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-18-2007 10:11 AM



Advertisments