Running one perl program after the other from a web browser using cgi

djnsh
djnsh used Ask the Experts™
on
I currently have a html webpage with three fields - a drop down box selector with five choices, and two text fields.

I am trying to write a cgi script which will will run three different sets of programs each found in five different directories which I am trying to get the interface to control. I effectively need the drop down box selector to govern which path the rest of the information has to go down. For example if the selection 'alpha' is chosen, the perl programs found in the alpha directory will be run, and so on for other choices.

I have written the html and javascript which validates the fields, and upon clicking submit will post the information to the corresponding cgi file, which is obviously non-existent at the moment.

However my question is how do I write a cgi script file which will run three different programs in succession?

The first program is usually run from the terminal as follows:

./search1.pl -file="names.1.list" -word="the" -output=temp/names

The arguments -file desginate the file to be searched, -word the word to look for in the file, and -output the destination to write the results of the search in temp (directory already created)

The remaining two programs simply sort the list into various orders. However the last program produces a statistics file which I write to a file   (normally using  >  followed by a filename) which is now needed to be output to the web browser instead as it simply contains text.

How do I do all this so that the name to call the -output file in the above example was taken from the html form field and the -word was taken from another field in the form submitted. I need to do this remember running the programs in succession. i.e: the search1.pl script obviously before the sorting files.

Many thanks with this problem - my experience with cgi is very limited (as you can probably tell!) however I have been writing simple perl scripts from the command line for a while now
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
i assume you aware of using the CGI module...

$var = param('param name');    # can be form elements, or url based params

use that for each form element you wish to get...

now with regard to your problem, im not totally sure about what it is you want... but...

you could use javascript to invoke the next script...

at the end of script one you could print to the browser...

print "<script language=\"javascript\" type=\"text/javascript\">window.location=\"nextscript.pl?param1=data&param2=moredata&param3=etc\"</script>";

now by doing that for the end of each script the next one will be invoked in the browser... you get the params using the CGI param() method described above...

Author

Commented:
To clarify what I am trying to do - here is a brief outline of what I need the interface to do:

1. A program I have written called search is run from the command line specifying parameters as shown previously.
2. The program searches several predefined files in a directory however for a different word each time a search is performed according to what the user wants to look for - e.g: in a batch file as shown below:

search -file="names.1.list" -word='"the" -output=temp/names1
search -file="names.2.list" -word="the" -output=temp/names2
search -file="names3.list" -word="the" -output=temp/names3
and so on.

What is supplied by the user in the html form is the -word to be searched. The output file names are written to a temporary directory I have created according to the number of input files there are present. The files names1, names2, etc will be written over each time a new search is performed so these are simply defined in the batch file.

What I need to find out is how do I write a batch file which will alter the -word section containing "the" according to what is specifiled in the html form field and then run the batch file which runs the programs. I currently run the batch file by doing ./searches from the terminal, where searches is the name I have given to the batch file.

All that is needed to be returned to the browser on the cgi page is a confirmation that the batch process has finished running.

Then my other programs which read what has been created in the temp directory are located in subsequent pages linking off from this page will contain further perl scripts which hopefully I will be able to work out how to write the cgi to run them based on how this problem is solved.

How do I do what I have outlined above - is it possible?

Many thanks for any help you can offer.

Author

Commented:
It may help if I outline in a number of steps what I am trying to do

1.  I have a program which accepts commands from the command line as shown in the previous postings

2. I have a batch file called searches which I run from the command line by doing ./searches which typically contains entries as shown below:
search1 -file="names.1.list" -word="the" -output=temp/names1
search1 -file="names.2.list" -word="the" -output=temp/names2
search1 -file="names.3.list" -word="the" -output=temp/names3
search1 -file="names.4.list" -word="the" -output=temp/names4
and so on.

I am trying to write an interface using cgi script which takes the word specified from the user in a form on the html page and replaces it in the batch file, in this example "the" would have been the word specified. The other fields remain fixed as each time a new search is intiiated, the fiiles name1, names 2, etc will simply be written over with the new search results.

Do I need to write each line in duplicate amongst the cgi code or can I refer to the external batch file and run it like a shell command bearing in mind where 'the' in the example above is listed will need to be replaced according to what is present in the html form field.

3. Subsequent pages will contain links to other perl programs which will read the temp directory files produced at this stage. How I write those will depend upon how this problem is solved.

Any help with how I solve this problem is greatly appreciated.

Author

Commented:
It may help if I outline in a number of steps what I am trying to do

1.  I have a program which accepts commands from the command line as shown above.

2. I have a batch file called searches which I run from the command line by doing ./searches which typically contains entries as shown below:
search1 -file="names.1.list" -word="the" -output=temp/names1
search1 -file="names.2.list" -word="the" -output=temp/names2
search1 -file="names.3.list" -word="the" -output=temp/names3
search1 -file="names.4.list" -word="the" -output=temp/names4
and so on.

I am trying to write a cgi script which takes the word specified from the user in a form on the html page and replaces it in the batch file, in this example "the" would have been the word specified. The other fields remain fixed as each time a new search is intiiated, the fiiles name1, names 2, etc will simply be written over with the new search results.

Do I need to write each line in duplicate or can I refer to external batch file and run it like a shell command bearing in mind where 'the in the example above is listed will need to be replaced according to what is present in the html form field.

3. Subsequent pages will contain links to other programs which will read the temp directory files produced at this stage. How I write those will depend upon how this problem is solved.

Any help with this problem is greatly appreciated.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial