Perl 脚本使用 CGI 与 echarts.js 生成 html。错误信息如下:
[Fri Aug 25 10:07:17.488252 2023] [cgi:error] [pid xx] [client xxxx] AH01215: (8)Exec format error: exec of '/cgi-bin/echarts.js' failed, referer: http://xxxx/cgi-bin/jindl_test.pl
[Fri Aug 25 10:07:17.488731 2023] [cgi:error] [pid xx] [client xxxx] End of script output before headers: echarts.js, referer: http://xxxx/cgi-bin/jindl_test.pl
脚本代码如下:
#!/usr/local/bin/perl5 -w
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use CGI qw(:cgi);
print "<html>\n";
print "<head>\n";
print "<title>test</title>\n";
print "<script src=\"echarts.js\"></script>\n";
print "</head>\n";
print "<body>\n";
print "<div id=\"main\" style=\"width: 600px;height:400px;\"></div>\n";
print "<script type=\"text/javascript\">";
print "var myChart = echarts.init(document.getElementById('main'));\n";
print "var option = {\n";
print "title: {text: 'Demo'},\n";
print "tooltip: {},\n";
print "xAxis: {data: ['Shirts', 'Cardigans', 'Chiffons', 'Pants', 'Heels', 'Socks']},\n";
print "yAxis: {type: 'value'},\n";
print "series: [\n";
print "{name: 'sales', data: [120, 200, 150, 120], type: 'line'},\n";
print "{name: 'values', data: [100, 300, 250, 100], type: 'line' }\n";
print "],\n";
print "legend: {data: ['sales','values']}\n";
print "};\n";
print "myChart.setOption(option);\n";
print "</script>\n";
print "</body></html>\n";
这个剧本有什么不合适的地方吗?
“执行格式错误”(ENOEXEC) 表示 shebang 行有问题。
#!
必须是文件的第一个字符。确保换行之前没有回车。确保 /usr/local/bin/perl5
存在,并且 Web 服务器用户可以执行它。尝试删除 -w
和任何尾随空格。