Hey all, I am thinking I'd like to "browserize" a number of simple functions, please correct me if I understand what I'd need to do. Lets say I want to run a pkginfo command on my web server, and return teh results to a browser, I'd need to call a ksh script from a CGI module? So I'd make a form in perl, where I could button select which packages I wanted to see, then pass those package names so in effect on the back end I could do a pkginfo |grep <FROM_WEB_FORM> So I can write the ksh easy, my question is how to call it and return the results I guess. I am sure this is all documented, and I know there's been a lot of talk of calling seperate programs from perl, does this fit? Can someone point me in the right direction for documentation on how to do this. Basically I need to be able to call ksh scripts and pass them operands, and parse the results into a list/form for a browser. Thanks, Jason
Ok so I let this go long enough without an answer :-).
Not sure where the ksh came from, you have Perl, why set your sights (pun not really intended) so low? The things you wish to accomplish should either be done completely in ksh or completely in Perl (I would suggest the second, but I am biased (very)). The discussions of calling separate programs from Perl are nice and possible, but when we can do something completely in a single language we should, IPC and shelling out should be left as a last resort. Having said that 'pkginfo' is a command already provided by the OS and a brief look on CPAN didn't show a heck of a lot, so in this case I would imagine you should shell out to it, but I would dispense with the piping to grep, and allow the power of Perl to trash the results :-).
I will assume you have chosen to use Perl...
In general Perl has two ways to call an external program (shelling out) there is the 'system' function,
perldoc -f system
Which is really intended only to call a program, let it do its thing and generate its side effects and then return either a good or bad result, and then there are the backticks, which probably have some fancy execution operator name, but who cares for now,
perldoc perlop (pretty sure they are in there somewhere).
In the latter case Perl returns not only a good bad result but also the output of the command (just as is provided using the pipe to grep) which is what we need/want. This output is returned into an array that we can then loop over using a 'foreach'. We then match on each of the array elements to see if it fits the choice from the form. Naturally we will want to use a full path to pkginfo and make sure to check the return value from the program, just as we do whenever shelling out. (perldoc noted above for system provides how to do that).
The easy part is wrapping all of this into a CGI script, which is where the CGI.pm module comes in. It makes all of this simple, and has extensive documentation,
perldoc CGI http://search.cpan.org/~lds/CGI.pm-3.05/CGI.pm
I leave that as an exercise for the reader. Give it a shot, come back when you have questions.
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
