By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Remote program execution using cgi-perl

P: 1
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:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use warnings;
  3. use CGI qw(:all);
  4. use CGI::Carp qw(fatalsToBrowser);
  5. use Fcntl qw(:flock);
  6. use strict;
  7.  
  8. my $dataFile="data.txt";
  9. print header(-type=>'text/html');
  10. print start_html("Internal Rate of Return Calculator");
  11.  
  12. my $value = `date`;
  13. print $value,"<br\>";
  14.  
  15. my $irr;
  16. if(!param)
  17. {
  18.     form();
  19.         print end_html(); 
  20. }
  21. else
  22. {
  23.    store();
  24.    result();
  25.    print end_html();
  26.  
  27. }
  28.  
  29. #-----------------------------------
  30. sub form(){
  31. print << "HERE";
  32. <form id="form" action="" method="POST"/>
  33. <h1> Welcome to IRR Calculator </h1>
  34. <p>Net-Present-Value: <input name="value" type="text"/></p>
  35. <p>Amortization-In-Years: <input name="years" type="text"/></p>
  36. <p>Monthly-Cashflow: <input name="monthly" type = "text"/></p>
  37. <p><input name="submit" type="submit" value="submit"/></p>
  38. </form>
  39. HERE
  40. }
  41.  
  42. #------------------------------------
  43. sub store(){
  44. my $value = param('value');
  45. my $years = param('years');
  46. my $monthly = param('monthly');
  47. open (DH, ">$dataFile") || die "Coudn't open the data file: $!";
  48. print DH $value, " ", $years, " ", $monthly;
  49. close(DH);
  50.  
  51. }
  52.  
  53. #-------------------------------------
  54. sub result(){
  55.     my $irr = `irr<data.txt`;
  56.     print $irr;    
  57. }
  58.  
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.
Oct 26 '07 #1
Share this Question
Share on Google+
1 Reply


KevinADC
Expert 2.5K+
P: 4,059
my $irr = `absolute/path/to/irr<data.txt`;
Oct 26 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.