Skip to content

Instantly share code, notes, and snippets.

@chill117
Created July 11, 2013 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chill117/5971522 to your computer and use it in GitHub Desktop.
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.
<?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