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.
I am having a doubt, i have written a CGI script to enter the HOSTNAME of my PC in text box.What i want to do:as soon as i enter the hostname in that textbox and press apply,the other cgi script called should change the hostname in /etc/hostname file of my system.
Please guide me for that?
Best guidance: don't do it. If your webserver is properly set up, it should disallow this anyway. Writing to files outside the web root should normally be disallowed. Writing to any system file by any non-root user (and who would run a web server as root?) should be absolutely disallowed.
Having said all of that, your concept of a CGI within a CGI is probably incorrect. Reading between the lines, I'd say you have used a CGI to generate an HTML page containing a form. On that form is a text entry, and an action attribute that points the form to a CGI that handles the form. The form generator and the form handler can be the same script, or can be different scripts. If the handler is the same as the generator, it would generally use some information passed from the form to distinguish what action is appropriate to perform. The concept of one CGI embedding another does not apply here.
--- rod.
What do you mean by 'calling a CGI from HTML'? HTML is markup language. A CGI is invoked by the HTTP server when an HTTP client (browser) fetches a URL prefixed with 'cgi-bin/' (or whatever directory name it has been configured to use). Where did you see the error message that you posted?
It would be useful at this juncture for you to post some code fragments (please use [CODE] tags to preserve source code) that demonstrate the problem, and also your 'solution'; calling a CGI from a CGI.
I could only speculate that your 'executable but not a CGI' is not outputting a valid HTTP header. You have said nothing about your implementation language, but a sample solution in Perl would be to use the header() method of the CGI package.
Code:
#! /usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:all/;
print header();
print start_html( -title => "My Perl CGI" );
#
# Your application goes here...
#
print end_html();
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.