Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

displaying command output on webpage using perl cgi

Tags:

linux

cgi

perl

below is the code, please give me any suggestions to display the result of the command output.

#!/usr/bin/perl
use strict; 
use warnings;
print "content-type:text/html\r\n\r\n";
print <<EOF;
<html>
<head><title>command</title></head>
<body>
EOF
my $d=qx(perl -cw 1.cgi);
print <<EOF;
<p>$d</p>
</body>
</html>
EOF
like image 573
sridhar reddy Avatar asked Jun 05 '26 12:06

sridhar reddy


1 Answers

qx will return the STDOUT in variable but you are trying to store the Perl compiling result into your variable, In Linux it is called as STDERR not a STDOUT so we need to do as follow

my $d=qx(perl -cw 1.cgi 2>&1);

More about 2>&1

like image 54
mkHun Avatar answered Jun 08 '26 02:06

mkHun