bory has asked for the wisdom of the Perl Monks concerning the following question:

Hi!
I'm trying to introduce in a CGI script(which takes the results of a html form)a particular command line for connecting to a database! I must use this command in its format but I don't know how to introduce it in the script because in every mode I've tried I had errors! The command is smth like this: <rsh"databasename" login password -W %a %a %a %a>
thank you!

update (broquaint): added a smattering of formatting

Replies are listed 'Best First'.
Re: code problems
by Zaxo (Archbishop) on Aug 28, 2003 at 15:04 UTC

    To run a system utility from perl, system, open, or exec. Use the LIST forms of argument to avoid shell interpolation.

    There. I've given you enough rope to shoot yourself in the foot and blow your leg clean off. It is dangerous to give web users a form to run arbitrary commands on your server. Be very very careful, use Safe, and learn something about the evil tricks one can pull before exposing yourself.

    After Compline,
    Zaxo

      Thank you very much for the system sugestion, but now i have a problem: i put the command in this way and it doesn't print anything: system("rsh xxx.aaa.yyy. 'source.login; find -p AXY -D | sort -c | bugval -a %a a'")! If I write system("rsh aaa.xxx.yyy") It's ok, i can connect! But i want to print the data so i write the entire command but it's error! Thanks for helping me again!
        Hi! I found how to do this : my $results=qx(rsh xxx.aaa.yyy. 'source.login; find -p AXY -D | sort -c | bugval -a %a a') and then in the script I put print "$results"; after print "Content-type:txt/html\n\n" Thank you!!!
Re: code problems
by blue_cowdawg (Monsignor) on Aug 28, 2003 at 15:06 UTC

    Instead of a command line consider using DBI in combination with a DBD driver to connect to the database. It will make your life much easier in the long run.


    Peter @ Berghold . Net

    Sieze the cow! Bite the day!

    Nobody expects the Perl inquisition!

    Test the code? We don't need to test no stinkin' code!
    All code posted here is as is where is unless otherwise stated.

    Brewer of Belgian style Ales

Re: code problems
by tcf22 (Priest) on Aug 28, 2003 at 15:47 UTC
    Be 'very' x 100 careful. This could cause a security hole that you could park a buick in. I would personally recommend DBI. Using DBI is probably quicker too, because you don't have to start another process. I haven't benchmarked it, so I'm not positive.
      I can tell you from experience that connecting the DBI way is much faster. We have Sybase, and two scripts checking ~1000 documents takes 59.23 using isql from the command line, and take 3:07 using DBI. The basic thing is that you have the disk read overhead.