我尝试在#!/bin/bash #### Used to set the type of script "bash"
set +xe #### Used to execute the script in debug mode (set +x) and e is used to receive the input from terminal
if [ x"$Link_A" == "x" ] ; then ##### condition check if x appending something is equal to x means no value in variable LinK_A
echo "Link_A parameter not set, DOESNOT execute FUNCTION" ##### print this line if above condition is true
else ###### if above condition is not true do below operation
cp -f ~/cached-resources/www.github.com/file1/executables/JenkinsScripts/jenkins_feed.pl ./jenkins_feed.pl
#####above line copy the file jenkis_feed.pl from specified directory to current dir forcefully
perl jenkins_feed.pl $JENKINS_HOME/feed_bts.ini $Link_A #### execute jenkil program which take two input parameter
fi
安装上运行的uhttpd server
上执行Cgi-Cpp程序。 Cgi文件是OpenWRT
并且也具有执行权限。我试图用HTML文件访问这个Cgi。这是我的/www/cgi-bin/sample.cgi
文件:
sample.cgi
单击HTML中的提交按钮时出现错误:
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <cgicc/CgiDefs.h>
#include <cgicc/Cgicc.h>
#include <cgicc/HTTPHTMLHeader.h>
#include <cgicc/HTMLClasses.h>
using namespace std;
using namespace cgicc;
int main () {
Cgicc formData;
cout << "Content-type:text/html\r\n\r\n";
cout << "<html>\n";
cout << "<head>\n";
cout << "<title>Using GET and POST Methods</title>\n";
cout << "</head>\n";
cout << "<body>\n";
form_iterator fi = formData.getElement("first_name");
if( !fi->isEmpty() && fi != (*formData).end()) {
cout << "First name: " << **fi << endl;
}else{
cout << "No text entered for first name" << endl;
}
cout << "</body>\n";
cout << "</html>\n";
return 0;
}
我错过了什么?所有权限都设置在那里。有什么建议吗?
答案 0 :(得分:1)
如果您尝试创建表单然后使用shell脚本然后使用c ++。在这里,我向您展示我如何创建一个文件,路由器可以在任何模式下设置,如dhcp,pppoe或static。
#!/bin/sh
echo "Content-type: text/html"
echo ""
echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '</head>'
echo '<br><h1><center>Welcome to Internet Service</center></h1>'
if [ -z "$QUERY_STRING" ]; then
ssi=$(uci get wireless.@wifi-iface[1].ssid)
key=$(uci get wireless.@wifi-iface[1].key)
net=$(uci get network.wan.netmask)
ipa=$(uci get network.wan.ipaddr)
lip=$(uci -P /var/state get network.lan.ipaddr)
ppu=$(uci get network.wan.username)
ppp=$(uci get network.wan.password)
ser=$(uci get network.wan.service)
gat=$(uci get network.wan.gateway)
rad=$(uci get network.wan.proto)
else
# No looping this time, just extract the data you are looking for with sed:
rad=`echo "$QUERY_STRING" | sed -n 's/^.*val_a=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
ssi=`echo "$QUERY_STRING" | sed -n 's/^.*val_b=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
key=`echo "$QUERY_STRING" | sed -n 's/^.*val_c=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
lip=`echo "$QUERY_STRING" | sed -n 's/^.*val_j=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
net=`echo "$QUERY_STRING" | sed -n 's/^.*val_d=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
ipa=`echo "$QUERY_STRING" | sed -n 's/^.*val_e=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
gat=`echo "$QUERY_STRING" | sed -n 's/^.*val_f=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
ppu=`echo "$QUERY_STRING" | sed -n 's/^.*val_g=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
ppp=`echo "$QUERY_STRING" | sed -n 's/^.*val_h=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
ser=`echo "$QUERY_STRING" | sed -n 's/^.*val_i=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
fi
echo '<body>'
echo "<form method=GET action=\"${SCRIPT}\">"
if [ $rad = "dhcp" ]; then
echo "<center><input type="radio" name="val_a" value="dhcp" checked> DHCP"\
'<input type="radio" name="val_a" value="static"> Static'\
'<input type="radio" name="val_a" value="pppoe"> PPPoE</center><br>'
elif [ $rad = "static" ]; then
echo "<center><input type="radio" name="val_a" value="dhcp"> DHCP"\
'<input type="radio" name="val_a" value="static" checked> Static'\
'<input type="radio" name="val_a" value="pppoe"> PPPoE</center><br>'
else
echo "<center><input type="radio" name="val_a" value="dhcp"> DHCP"\
'<input type="radio" name="val_a" value="static"> Static'\
'<input type="radio" name="val_a" value="pppoe" checked> PPPoE</center> <br>'
fi
echo "<table nowrap align="center">"\
'<tr><td> SSID:</TD><TD><INPUT type="textarea" rows=1 name="val_b" size=12 value="'$ssi'" autofocus></td></tr>'\
'<tr><td> WiFi Password:</td><td><INPUT type="textarea" rows=1 name="val_c" size=12 value="'$key'" maxlength="16" minlength="8"></td></tr>'\
'<table nowrap align="center">'\
'<center>(Password should be of 8 characters)</center>'\
'<tr><td><br> LAN IPaddress:</td><td><br><INPUT type="textarea" rows=1 name="val_j" size=12 value="'$lip'"></td></tr>'\
'<table nowrap align="center" style="border:2px solid;" cellspacing="5" cellpadding="5"><caption>Static Settings:-</caption>'\
'<tr><td> Subnet Mask:</td><td><INPUT type="textarea" rows=1 name="val_d" size=12 value="'$net'"></td></tr>'\
'<tr><td> IPaddress:</td><td><INPUT type="textarea" rows=1 name="val_e" size=12 value="'$ipa'"></td></tr>'\
'<tr><td>Default Gateway:</td><td><INPUT type="textarea" rows=1 name="val_f" size=12 value="'$gat'"></td></tr><br>'\
'<table nowrap align="center" style="border:2px solid;" cellspacing="5" cellpadding="5"><caption>PPPoE Settings:-</caption>'\
'<tr><td> PPPoE Username:</TD><TD><INPUT type="textarea" rows=1 name="val_g" size=12 value="'$ppu'"></td></tr>'\
'<tr><td> PPPoE Password:</TD><TD><INPUT type="textarea" rows=1 name="val_h" size=12 value="'$ppp'"></td></tr>'\
'<tr><td> Service Name:</TD><TD><INPUT type="textarea" rows=1 name="val_i" size=12 value="'$ser'"></td></tr><br>'\
'</table></table></table>'
echo '<center><br><input type="submit" style="width:80px;height:35px;" value="Save"></form>'
# Make sure we have been invoked properly.
if [ "$REQUEST_METHOD" != "GET" ]; then
echo "<hr>Script Error:"\
"<br>Usage error, cannot complete request, REQUEST_METHOD!=GET."\
"<br>Check your FORM declaration and be sure to use METHOD=\"GET\".<hr>"
exit 1
fi
# If no search arguments, exit gracefully now.
if [ -z "$QUERY_STRING" ]; then
exit 0
else
# No looping this time, just extract the data you are looking for with sed:
rad=`echo "$QUERY_STRING" | sed -n 's/^.*val_a=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
ssi=`echo "$QUERY_STRING" | sed -n 's/^.*val_b=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
key=`echo "$QUERY_STRING" | sed -n 's/^.*val_c=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
lip=`echo "$QUERY_STRING" | sed -n 's/^.*val_j=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
net=`echo "$QUERY_STRING" | sed -n 's/^.*val_d=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
ipa=`echo "$QUERY_STRING" | sed -n 's/^.*val_e=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
gat=`echo "$QUERY_STRING" | sed -n 's/^.*val_f=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
ppu=`echo "$QUERY_STRING" | sed -n 's/^.*val_g=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
ppp=`echo "$QUERY_STRING" | sed -n 's/^.*val_h=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
ser=`echo "$QUERY_STRING" | sed -n 's/^.*val_i=\([^&]*\).*$/\1/p' | sed "s/%20/ /g" | sed "s/%40/@/g" | sed "s/%28/(/g" | sed "s/%29/)/g" | sed "s/%25/%/g" | sed "s/%2B/+/g" | sed "s/%23/#/g" | sed "s/%21/!/g" | sed "s/%24/$/g" | sed "s/%5E/^/g" | sed "s/%3D/=/g" | sed "s/%7E/~/g" | sed "s/%7C/|/g" | sed "s/%7B/{/g" | sed "s/%7D/}/g" | sed "s/%5B/[/g" | sed "s/%5D/]/g" | sed "s/%3A/:/g" | sed "s/%3B/;/g" | sed "s/%3F/?/g" | sed "s/%2C/,/g" | sed "s/%3C/</g" | sed "s/%3E/>/g"`
t1=$(ifdown wan)
t2=$(uci set wireless.@wifi-iface[1].ssid=$ssi)
t3=$(uci set wireless.@wifi-iface[1].encryption=psk2)
t4=$(uci set wireless.@wifi-iface[1].key=$key)
t5=$(uci commit wireless)
t5=$(ifup wan)
t6=$(wifi)
t16=$(uci set network.lan.ipaddr=$lip)
t7=$(uci set network.wan.proto=$rad)
t8=$(uci set network.wan.username=$ppu)
t9=$(uci set network.wan.password=$ppp)
t10=$(uci set network.wan.service=$ser)
t11=$(uci set network.wan.netmask=$net)
t12=$(uci set network.wan.ipaddr=$ipa)
t13=$(uci set network.wan.gateway=$gat)
t14=$(uci commit network)
t15=$(/etc/init.d/network restart)
fi
echo '</body>'
echo '</html>'
exit 0
只需从html调用此文件,它将在任何浏览器中打开 注意: - 授予此文件777的权限,并且不对此文件提供任何扩展名。只需通过提供名称即可保存。
答案 1 :(得分:1)
确保正确构建程序。首先打开一个终端窗口并cd到/ www / cgi-bin。现在使用
ls -l
列出目录中的程序。你应该在那里看到你的sample.cpp文件。如果不存在,请将其移至那里。如果您不再拥有sample.cpp文件,请使用最初发布的代码创建文本文件。您可以使用像nano这样的文本编辑器来完成此操作。
nano sample.cpp
输入或粘贴源文件。然后按ctrl-x保存并退出程序。确保告诉nano保存程序而不是退出。
接下来删除现有的sample.cgi。不要删除sample.cpp。
使用此命令将源代码(sample.cpp)构建为二进制可执行文件:
g++ sample.cpp -o sample.cgi
&#34; -o&#34;是字母&#34; o&#34;而不是数字&#34; 0&#34;。如果构建引发编译错误,请修复错误并重复,直到成功构建程序。您现在将拥有一个二进制文件&#34; sample.cgi&#34;。
确保&#34; sample.cgi&#34;是可执行的。如果没有,那么使用
使其可执行sudo chmod a+x sample.cgi
确保您可以先从命令行执行sample.cgi。如果你不能这样做,那么服务器也无法做到。然后输入
"./sample.cgi".
在执行应用程序后,您应该会在终端窗口中看到您从应用程序发送的html。
如果您需要进一步的帮助,请告诉我们。