Forum Moderators: coopster

Message Too Old, No Replies

Execute external program via PHP

         

ktsirig

5:44 pm on Oct 1, 2005 (gmt 0)

10+ Year Member



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 commend-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.
By the way, the command which I use when I write the script in the command line is :

program_name [argument1 -> A database file] [argument2 -> info supplied by user]

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?

Thanx a lot!

mcibor

9:00 pm on Oct 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you using a database program? If yes, then it may be easier to use the php built in functions to operate on that database.

If not you may use really all of these functions. Only remember, that you are executing them as the user apache!

echo shel_exec("ps -ax");

Best regards
Michal Cibor

However be VERY careful while passing GET value into the exec functions, as it may be really harmful to your system!

dmmh

9:03 pm on Oct 1, 2005 (gmt 0)

10+ Year Member



I may be entirely wrong here since I do not use flat text files or system commands myself, but isnt what you are trying to to possible in a far less dangerous way?

As far as I know, it is a wise thing to reduce the amount of system() or exec() calls to a minimum. Seems to me what you are trying to do can be done with simple readfile() function calls etc

but then again, I might be wrong

dmmh

9:04 pm on Oct 1, 2005 (gmt 0)

10+ Year Member



and 2 alike minds met :)

ktsirig

9:29 pm on Oct 1, 2005 (gmt 0)

10+ Year Member



Thanx to both of you for your time!
I asked about these functions, because 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].

That's why I can't find another way to do it...
Do you think it would help if I did anything with Perl? A kind of CGI-script?

mcibor

10:28 pm on Oct 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For search scripts I would recommend database, eg. MySQL - free, easy to use, optimalized for searches.

Here you can find a simple search script

[onlamp.com...]

Best regards
Michal Cibor

ktsirig

8:05 am on Oct 2, 2005 (gmt 0)

10+ Year Member



Thanx for the answer, but the problem I have isn't at all connected with Mysql.
I have a PHP page containing a textarea.
User inserts text data into the textarea.
Those data are used as input for the external program (hmmpfam.exe).
Tha program runs in command line as

hmmpfam.exe [file] [user data]

I only need to 'tell' the hmmpfam program to start running, using the [user data]..

coopster

11:23 pm on Oct 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Is your question then, how do I get the "user data" portion of this into my shell command?

jatar_k

3:18 pm on Oct 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



as an aside, a lot of hosts don't allow these functions

shell_exec, passthru, exec, system, proc_open, cmd

and there are a few others too. It will more than likely become more common to disable these functions in shared environments.