Created
July 11, 2013 00:36
-
-
Save chill117/5971522 to your computer and use it in GitHub Desktop.
Provides the command_exists() method, which will test to see if the given shell command exists.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/* | |
|---------------------------------------------------------------- | |
| Description | |
|---------------------------------------------------------------- | |
Provides the command_exists() method, which will test to see if | |
the given shell command exists. | |
|---------------------------------------------------------------- | |
| Dependencies | |
|---------------------------------------------------------------- | |
CodeIgniter | |
|---------------------------------------------------------------- | |
| Example Usage | |
|---------------------------------------------------------------- | |
<?php | |
if (command_exists('vim')) | |
echo 'yay!'; | |
else | |
echo ':('; | |
?> | |
Should print the following, if vim is installed on your server: | |
yay! | |
*/ | |
function command_exists($cmd) | |
{ | |
// Clean the command. | |
$cmd = str_replace(array("\0", '/', ',', ';', '|'), '', $cmd); | |
$return = shell_exec('which ' . $cmd); | |
return !empty($return); | |
} | |
/* End of file shell_helper.php */ | |
/* Location: ./application/helpers/shell_helper.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment