40 users online (0 members and 40 guests)  


  Results 1 to 2 of 2

Related

  1. Running external program from CGI/Perl    Forum: CGI Perl Forum
    Replies: 2
  2. Execute external program in perl/cgi    Forum: CGI Perl Forum
    Replies: 2
  3. remote connect to Mysql    Forum: PHP Forum
    Replies: 8
  4. MySQL remote access?    Forum: Web Hosting Forum
    Replies: 6
  1. #1
    jasper's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2007
    Posts
    1

    Remote program execution using cgi-perl

    Hello,
    I am developing a cgi-perl script that takes some value from a html form as input and stores them in a data file. I have a program called "irr" in my server, it is executed just by typing irr at the shell prompt. Upon execution the program first displays a line describing the types of input required and waits for the input in the next line.I intend to pass the inputs from the values stored in the data file by the script. The following is the code that i came up with:


    #!/usr/bin/perl -w
    use warnings;
    use CGI qw(:all);
    use CGI::Carp qw(fatalsToBrowser);
    use Fcntl qw(:flock);
    use strict;

    my $dataFile="data.txt";
    print header(-type=>'text/html');
    print start_html("Internal Rate of Return Calculator");

    my $value = `date`;
    print $value,"<br\>";

    my $irr;
    if(!param)
    {
    form();
    print end_html();
    }
    else
    {
    store();
    result();
    print end_html();

    }

    #-----------------------------------
    sub form(){
    print << "HERE";
    <form id="form" action="" method="POST"/>
    <h1> Welcome to IRR Calculator </h1>
    <p>Net-Present-Value: <input name="value" type="text"/></p>
    <p>Amortization-In-Years: <input name="years" type="text"/></p>
    <p>Monthly-Cashflow: <input name="monthly" type = "text"/></p>
    <p><input name="submit" type="submit" value="submit"/></p>
    </form>
    HERE
    }

    #------------------------------------
    sub store(){
    my $value = param('value');
    my $years = param('years');
    my $monthly = param('monthly');
    open (DH, ">$dataFile") || die "Coudn't open the data file: $!";
    print DH $value, " ", $years, " ", $monthly;
    close(DH);

    }

    #-------------------------------------
    sub result(){
    my $irr = `irr<data.txt`;
    print $irr;
    }

    ----------------------------------------------------------------
    Unfortunately the result is never displayed on the browser. I have tried using the command : `irr<data.txt | cat` but that doesn't work either. Where am I doing wrong? A little help would be greatly appreciated. Thank you.

  2. #2
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: Remote program execution using cgi-perl

    Is the STORE and PRINT END HTML working properly?
    How getting the data from the file in this way...
    Code:
     
    open (LOG, "<data.txt") || die "Error";
    flock (LOG, 2) || die "Error";
    my @log = <LOG>;
    close (LOG) || die "Error";
    now all the contents of data.txt is stored into @log (which can then be manipulated if you wish to take particular data items) etc etc.
    Does this help?



Tags for this Thread