Sunday, May 10, 2009

PHP: How to run external command using php?

How to run an external command using PHP at windows which will not display the output of external command on screen?

I'll suggest you to use exec() function of PHP. This will be helpful when you are using Windows OS. Let say you are running the windows DIR command from your PHP script, and you don't want to show the output on screen.

For this example, the exec() function takes the command as parameter, and the output array as parameter. And after executing the command from php, it returns the output inside your output array.
$output = array();
exec('dir', $output);

Inside the example, I have initialized the array as empty. It is always better to do like this while using exec() function. Otherwise it will append the new values after previously one.

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...