ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Im trying to set this up, and right now to do what it needs to its great. All it does is runs a cgi script that opens a C programs with a given input, coded into the CGI. I want to create and html file that can use a for with check boxes to send a combination of data to a similar cgi file. Let me show you the code, it will help.
The first cgi:
Code:
#!/bin/sh
# Parallel port CGI script
# This would be controller.cgi, obviously my form will not do anything to supply this
# Send HTTP headers
echo Content-type: text/html;charset=ISO-8859
echo
# Do the controlling
/usr/sbin/lptest 0 /*<----This is what i want to be able to change, with any value from 0 to 255*/
# Output web page data
echo "<html><head></head><body>"
echo "Parallel port controlled<br>"
echo "<a href=\"/link1.html\">Go back to controlling page</a>"
echo "</body></html>"
#
And what i would do (kinda, just missing the actual working parts :rollseyes
My hope was to make one checkbox worth 1, one worth 2, one worth 4, etc up to 8, and add these together then send that number to the cgi so that it can run my C file (which im using from HeRe )
How do I edit the two files? Sorry for the excessive amount of code, its really simple probably to you guys I just wasnt sure how to explain my question. Thanks a ton!
Its really is a mess, but thanks a ton secesh. I'll try to make it more readable. What you made worked great!
well... this is a cluster-f***
first- comment what script belongs to what filename
second- this is not CGI -- you're throwing around all kinds of files -- an sh script, a reference to an asp page...
third -- i have no real idea of what you're trying to accomplish, but here's how you throw form data around with perl. Also, i'm a little rusty, and not going to test this, so it is what it is.
Code:
#!/usr/bin/perl
###########
## Moray ##
###########
## filename: parallel.cgi
#
print "Content-Type: text/html\n\n";
use CGI;
my $q = new CGI;
## TODO: Error catch!
system("/usr/sbin/lptest ".$q->param("my_val"));
# Output web page data
print "<html><head></head><body>";
print "Parallel port controlled<br>";
print "<a href=\"/link1.html\">Go back to controlling page</a>";
print "</body></html>";
and the html file includes this form with action to parallel.cgi
#!/usr/bin/perl
###########
## filename: lpton2.cgi
#
print "Content-Type: text/html\n\n";
use CGI;
my $q = new CGI;
## TODO: Error catch!
$tot=0;
for($coun=0;$coun<=7;$coun++)
{
if ($q->param("Pin_".($coun+1))=="on")
{
$tot+=2**$coun;
};
};
system("/usr/sbin/lptest ".$tot);
# Output web page data
print $tot;
print "<html><head></head><body>";
print "Parallel port controlled<br>";
print "<a href=\"/link1org.html\">Go back to controlling page</a>";
print "</body></html>";
Yeah, the user and pass do nothing yet, but thats ok. It's stupid anyways. But why is my conditional statement " if ($q->param("Pin_".($coun+1))=="on") " always coming back true??
Wow, thanks, switched it to eq and its working great! Is eq equivalent to =?
Nevermind, I see, I need it for a string conditional. This is great, i have username and pass stuff working too now.. Thanks again!
perl handles variables a little differently. it does not make a difference between string variables and numerical variables, they are all 'scalars' to perl.
therefore, you must watch what operators you use while manipulating scalars:
eq is NOT the same as ==.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.