Missing output when running system command in perl/cgi file

Posted by aladine on Stack Overflow See other posts from Stack Overflow or by aladine
Published on 2010-03-31T14:43:07Z Indexed on 2010/04/01 2:13 UTC
Read the original article Hit count: 416

I need to write a CGI program and it will display the output of a system command:

script.sh

echo "++++++"  
VAR=$(expect -c " spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD match_max 
100000 expect \"*?assword:*\" send -- \"$PASS\r\" send -- \"\r\" expect eof ") 
echo $VAR 
echo "++++++"

In CGI file:

my $command= "ksh ../cgi-bin/script.sh";
my @output= `$command`; 
print @output;

Finally, when I run the CGI file in unix, the $VAR is a very long string including \n and some delimiters. However, when I run on web server, the output is

++++++

++++++

So $VAR is missing when passing in the web interface/browser. I know maybe the problem is $VAR is very long string.

But anyway, is there anyway to solve this problem except writing the output to a file then retrieve it from browser?

Thanks if you are interested in my question.

© Stack Overflow or respective owner

Related posts about cgi

Related posts about shell-scripting