Forum Moderators: coopster

Message Too Old, No Replies

about system commands

save results

         

ktsirig

1:02 pm on Oct 12, 2005 (gmt 0)

10+ Year Member



Hi all!
I call a system program through PHP, using the system commands provided by PHP (like system, exec etc)

Q1: Is there a way (I think using the return values) to make sure that the program has run? I mean, not take the data from the program if the program has encountered any kind of internal error and didn't ran correctly.

Q2: How can I pass the data that I take from the program to a string, in order to handle them and present them to the user the way I want?

The command I use is something like:

$command = shell_exec ('program_name argum1 argum2');

argum1 and argum2 are arguments that I feed the program with.
Will the '> tmp_file' store the data I take as result from the program into the tmp_file or must I use something else?
Thanx

jatar_k

3:08 pm on Oct 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, if you are using shell_exec then

[php.net...]

shell_exec -- Execute command via shell and return the complete output as a string

so it returns the output from the program/script/whatever as a string already. I would make the program return strings that have some checkable value and then you will be able to test for those values and see whether there was success or failure.

to be noted:
using these system commands is very dangerous, make sure any info passed to them is properly cleaned otherwise you are in for some very large security issues.

StupidScript

6:19 pm on Oct 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about:

Q1:

$command = shell_exec ('program_name argum1 argum2');

if (!$command) {

...execution problem...

}

Q2:

$command = shell_exec ('program_name argum1 argum2');

echo $command;

$command
contains the output from the executed instruction.

On a 'Nix box:

shell_exec ("program_name argum1 argum2 > 'some_file'");

will pipe the result to 'some_file', given the proper permissions, etc.

And I do agree (as usual) with jatar_k ... clean that data. System executions can be very dangerous when bad data is passed to them.