PHP/ command-line program

They have: 53 posts

Joined: Oct 2005

Hi all,
I need to execute a command-line program through PHP.
I have a form which includes a textarea, where the user writes his data.
These data will be used as input for the command-line program.
Will I go something like:

$data = $_GET['info'];
Which function shall I use? System, exec, shell_exec, passthru?
I can't choose which one is the correct.

The programm running in the command-line is an biological algorithm which is complicated, and, of course not written by me, so I could interfere with the code.
It is an .exe program, called hmmpfam, so in the command line, I write:

hmmpfam [file in hard disk] [data submitted]

and the algorithm searches the [file in hard disk] for patterns that match the [data submitted].

So, in the function that will be used, the data supplied by the user will be passed as my second argument (the 1st argument is a file in my hard disk).

And, lastly, do I need to change any global settings for PHP in order to perform such actions, ie running scripts via PHP programs???

Do you think it would help if I did anything with Perl? A kind of CGI-script??? I read tha PHP's functions are not wise to use in those cases...
Thanx a lot!

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

I cannot fully answer your message right now (just finished getting the slideshow done for church in the morning, and have to be there at 10am).

However, jsut in case it isn't mentioned by someone else, MAKE SURE YOU VALIDATE what is in that textbox being sent to a system command. Left unchecked that could so easuily be used to do things you do not mean it to.

I will try to reply later tomorrow.

-Greg

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.