Problem printing array content with CGI

S

Simon L

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
 
S

Shawn Corey

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
 
G

Gunnar Hjalmarsson

Shawn said:
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.
 
S

Simon L

Gunnar Hjalmarsson said:
Relative paths is a rather common cause as well.


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
 
S

Simon L

Steve May said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top