本文整理汇总了PHP中shell_exec函数的典型用法代码示例。如果您正苦于以下问题:PHP shell_exec函数的具体用法?PHP shell_exec怎么用?PHP shell_exec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shell_exec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sassProcessing
private function sassProcessing()
{
global $IP, $wgSassExecutable, $wgDevelEnvironment;
wfProfileIn(__METHOD__);
$tempDir = sys_get_temp_dir();
//replace \ to / is needed because escapeshellcmd() replace \ into spaces (?!!)
$tempOutFile = str_replace('\\', '/', tempnam($tempDir, 'Sass'));
$tempDir = str_replace('\\', '/', $tempDir);
$params = urldecode(http_build_query($this->mParams, '', ' '));
$cmd = "{$wgSassExecutable} {$IP}/{$this->mOid} {$tempOutFile} --cache-location {$tempDir}/sass -r {$IP}/extensions/wikia/SASS/wikia_sass.rb {$params}";
$escapedCmd = escapeshellcmd($cmd) . " 2>&1";
$sassResult = shell_exec($escapedCmd);
if ($sassResult != '') {
Wikia::log(__METHOD__, false, "commandline error: " . $sassResult . " -- Full commandline was: {$escapedCmd}", true);
Wikia::log(__METHOD__, false, "Full commandline was: {$escapedCmd}", true);
Wikia::log(__METHOD__, false, AssetsManager::getRequestDetails(), true);
if (file_exists($tempOutFile)) {
unlink($tempOutFile);
}
if (!empty($wgDevelEnvironment)) {
$exceptionMsg = "Problem with SASS processing: {$sassResult}";
} else {
$exceptionMsg = 'Problem with SASS processing. Check the PHP error log for more info.';
}
throw new Exception("/* {$exceptionMsg} */");
}
$this->mContent = file_get_contents($tempOutFile);
unlink($tempOutFile);
wfProfileOut(__METHOD__);
}
示例2: getSuggestion
function getSuggestion($word)
{
if ($fh = fopen($this->tmpfile, "w")) {
fwrite($fh, "!\n");
fwrite($fh, "^{$word}\n");
fclose($fh);
} else {
die("Error opening tmp file.");
}
$data = shell_exec($this->cmd);
$returnData = array();
$dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);
foreach ($dataArr as $dstr) {
$matches = array();
// Skip this line.
if (strpos($dstr, "@") === 0) {
continue;
}
preg_match("/\\& .* .* .*: (.*)/i", $dstr, $matches);
if (!empty($matches[1])) {
// For some reason, the exec version seems to add commas?
$returnData[] = str_replace(",", "", $matches[1]);
}
}
return $returnData;
}
示例3: main
/**
* Calculates Time for the repository this shell is run in and prints to screen
*
* @return void
* @access public
*/
function main()
{
$committerName = '';
$committer = null;
$totalTime = 0;
if (isset($this->args[0])) {
foreach ($this->args as $key => $anArg) {
if ($key === count($this->args) - 1) {
$committerName .= $anArg;
} else {
$committerName .= $anArg . " ";
}
}
$committer = " --committer='{$committerName}'";
}
$this->out("Running: git --no-pager log --all-match --pretty=oneline --grep=[0-9].{$committer}");
$this->out('');
$output = shell_exec("git --no-pager log --all-match --pretty=oneline --grep=[0-9].{$committer}");
$this->out('Commits with CodebaseHQ times:');
$this->out($output);
preg_match_all("{T[0-9]+}", $output, &$matches);
foreach ($matches['0'] as $match) {
preg_match_all("{[0-9]+}", $match, &$out);
$totalTime += $out['0']['0'];
}
$hours = floor($totalTime / 60);
$mins = $totalTime % 60;
if (isset($this->args[0])) {
$this->out("Committer {$committerName} took approximately {$hours} Hours {$mins} Minutes ");
} else {
$this->out("Current project has taken a total time of {$hours} Hours {$mins} Minutes ");
}
}
示例4: _shell_exec
public static function _shell_exec($cmd)
{
# string shell_exec ( string $cmd )
# returns command output
$back = shell_exec($cmd);
return array(false, $back);
}
示例5: dieIfDirectoriesNotWritable
/**
* Checks that the directories Piwik needs write access are actually writable
* Displays a nice error page if permissions are missing on some directories
*
* @param array $directoriesToCheck Array of directory names to check
*/
public static function dieIfDirectoriesNotWritable($directoriesToCheck = null)
{
$resultCheck = self::checkDirectoriesWritable($directoriesToCheck);
if (array_search(false, $resultCheck) === false) {
return;
}
$directoryList = '';
foreach ($resultCheck as $dir => $bool) {
$realpath = Filesystem::realpath($dir);
if (!empty($realpath) && $bool === false) {
$directoryList .= self::getMakeWritableCommand($realpath);
}
}
// Also give the chown since the chmod is only 755
if (!SettingsServer::isWindows()) {
$realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/');
$directoryList = "<code>chown -R www-data:www-data " . $realpath . "</code><br />" . $directoryList;
}
if (function_exists('shell_exec')) {
$currentUser = trim(shell_exec('whoami'));
if (!empty($currentUser)) {
$optionalUserInfo = " (running as user '" . $currentUser . "')";
}
}
$directoryMessage = "<p><b>Piwik couldn't write to some directories {$optionalUserInfo}</b>.</p>";
$directoryMessage .= "<p>Try to Execute the following commands on your server, to allow Write access on these directories" . ":</p>" . "<blockquote>{$directoryList}</blockquote>" . "<p>If this doesn't work, you can try to create the directories with your FTP software, and set the CHMOD to 0755 (or 0777 if 0755 is not enough). To do so with your FTP software, right click on the directories then click permissions.</p>" . "<p>After applying the modifications, you can <a href='index.php'>refresh the page</a>.</p>" . "<p>If you need more help, try <a href='?module=Proxy&action=redirect&url=http://piwik.org'>Piwik.org</a>.</p>";
Piwik_ExitWithMessage($directoryMessage, false, true);
}
示例6: read_osx_system_profiler
public static function read_osx_system_profiler($data_type, $object, $multiple_objects = false, $ignore_values = array())
{
$value = $multiple_objects ? array() : false;
if (pts_client::executable_in_path('system_profiler')) {
$info = trim(shell_exec('system_profiler ' . $data_type . ' 2>&1'));
$lines = explode("\n", $info);
for ($i = 0; $i < count($lines) && ($value == false || $multiple_objects); $i++) {
$line = pts_strings::colon_explode($lines[$i]);
if (isset($line[0]) == false) {
continue;
}
$line_object = str_replace(' ', null, $line[0]);
if (($cut_point = strpos($line_object, '(')) > 0) {
$line_object = substr($line_object, 0, $cut_point);
}
if (strtolower($line_object) == strtolower($object) && isset($line[1])) {
$this_value = trim($line[1]);
if (!empty($this_value) && !in_array($this_value, $ignore_values)) {
if ($multiple_objects) {
array_push($value, $this_value);
} else {
$value = $this_value;
}
}
}
}
}
return $value;
}
示例7: index
public function index()
{
$filename = "s.pdf";
$content = shell_exec('pdftotext -raw ' . $filename . ' -');
$separator = "\r\n";
$line = strtok($content, $separator);
$i = 0;
$j = 0;
while ($line !== false) {
$i++;
if ($line == 'Issue') {
$j++;
$data = new stdClass();
$data->muhasil = strtok($separator);
$data->jumlah = strtok($separator);
$data->no_m1 = strtok($separator);
$data->periode = strtok($separator);
$data->nama = strtok($separator);
$data->aims = strtok($separator);
list($data->tanggal, $data->metode) = explode(' ', strtok($separator));
while (($line = strtok($separator)) != 'Issue' && ord($line[0]) != 12) {
$data->rincian[] = $line;
}
var_dump($data);
echo '<br/>------------------------------------<br/>';
} else {
$line = strtok($separator);
}
}
}
示例8: updateCodes
function updateCodes($parameters, $arg1 = '', $arg2 = '', $arg3 = '')
{
$mode = "pull";
$shellResult = "";
if ($arg1 or $arg2 or $arg3) {
$mode = $arg1 ? $arg1 : $mode;
}
if (is_array($parameters)) {
$mode = array_key_exists("mode", $parameters) ? $parameters['mode'] : $mode;
}
switch ($mode) {
case "push":
break;
default:
set_time_limit(60);
$shellResult .= shell_exec("svn up ../");
$directories = zig("dbTableApplications", "getApplicationDirectories");
foreach ($directories as $directory) {
switch (substr($directory, 0, 4) != "zig-") {
case true:
set_time_limit(60);
$shellResult .= shell_exec("cd ../{$directory}");
$shellResult .= shell_exec("git {$mode}");
}
}
}
$zigReturn['value'] = $shellResult;
return $zigReturn;
}
示例9: installCentreon
/**
*
*/
public static function installCentreon()
{
if (Migrate::checkForMigration()) {
Migrate::migrateCentreon();
} else {
// Initialize configuration
$di = Di::getDefault();
$config = $di->get('config');
$centreonPath = $config->get('global', 'centreon_path');
$dbName = $config->get('db_centreon', 'dbname');
// Check Php Dependencies
$phpDependencies = json_decode(file_get_contents(rtrim($centreonPath, '/') . '/install/dependencies.json'));
PhpDependencies::checkDependencies($phpDependencies);
echo Colorize::colorizeMessage("Starting to install Centreon 3.0", "info") . "\n";
echo "Creating " . Colorize::colorizeText('centreon', 'blue', 'black', true) . " database... ";
// Install DB
$migrationManager = new Manager('core', 'production');
$migrationManager->generateConfiguration();
$cmd = self::getPhinxCallLine() . 'migrate ';
$cmd .= '-c ' . $migrationManager->getPhinxConfigurationFile();
$cmd .= ' -e core';
shell_exec($cmd);
//Db::update('core');
echo Colorize::colorizeText('Done', 'green', 'black', true) . "\n";
$modulesToInstall = self::getCoreModules();
$dependencyResolver = new Dependency($modulesToInstall['modules']);
$installOrder = $dependencyResolver->resolve();
foreach ($installOrder as $moduleName) {
$currentModule = $modulesToInstall['modules'][$moduleName];
$moduleInstaller = new $currentModule['classCall']($currentModule['directory'], $currentModule['infos'], 'console');
$moduleInstaller->install();
}
echo Colorize::colorizeMessage("Centreon 3.0 has been successfully installed", "success") . "\n";
}
}
示例10: GitUpdate
/**
* Automatically update from the git master (if configured)
*
*/
function GitUpdate()
{
if (GetSetting('gitUpdate')) {
echo "Updating from GitHub...\n";
echo shell_exec('git pull origin master');
}
}
示例11: genSchoolCertificates
function genSchoolCertificates($schoolID)
{
shell_exec("rm -rf " . CERTIGEN_EXPORTDIR . "/" . $schoolID);
mkdir(CERTIGEN_EXPORTDIR . "/" . $schoolID, $code = 0777, $recursive = true);
list($aGroups, $aContestants) = getGroupsAndContestants($schoolID);
$nbStudents = count($aContestants);
if ($nbStudents == 0) {
return 0;
}
foreach ($aContestants as $contestant) {
$contestant->Group->certificates .= getHtmlCertificate($contestant);
$contestant->Group->contestants[] = $contestant;
}
$groupsHtml = "";
foreach ($aGroups as $groupID => $group) {
$groupHtml = getGroupContestantsList($group, $schoolID);
$groupHtml .= $group->certificates;
$groupFullHtml = file_get_contents("school_template.html");
$groupFullHtml = str_replace("{groups}", $groupHtml, $groupFullHtml);
file_put_contents("certificates_group.html", $groupFullHtml);
$groupPdf = CERTIGEN_EXPORTDIR . '/' . CertiGen::getGroupOutput($groupID, $schoolID) . '.pdf';
shell_exec("bash wkhtmltopdf.sh -O landscape -T 5 -B 5 certificates_group.html " . $groupPdf);
$groupsHtml .= $groupHtml;
}
$schoolHtml = file_get_contents("school_template.html");
$schoolHtml = str_replace("{groups}", $groupsHtml, $schoolHtml);
file_put_contents("certificates_school.html", $schoolHtml);
$outPdf = CERTIGEN_EXPORTDIR . '/' . CertiGen::getSchoolOutput($schoolID) . '.pdf';
shell_exec("bash wkhtmltopdf.sh -O landscape -T 5 -B 5 certificates_school.html " . $outPdf);
return $nbStudents;
}
示例12: finalize
/**
* Finalises the archive by compressing it. Overrides parent's method
* @return boolean TRUE on success, FALSE on failure
*/
function finalize()
{
// Get gzip's binary location
$registry = JoomlapackModelRegistry::getInstance();
$gzip = escapeshellcmd($registry->get('gzipbinary'));
// Construct and run command line
$command = "{$gzip} " . escapeshellcmd($this->_tempFilename);
JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackPackerTARGZ :: Calling gzip. The command line is:");
JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, $command);
$result = shell_exec($command);
// Normally, gzip should be silent as a fish. If anything was sput out,
// there must have been an error.
if (strlen(trim($result)) > 0) {
$errorMessage = "Error calling gzip: " . $result . " \n Command line was: \n " . $command . " \n Please check file permissions and examine the result message for any hints regarding the problem tar faced archiving your files.";
$this->setError($errorMessage);
return false;
}
// Now, unregister the temp file (which no longer exists), register the gzipped file as
// a new temp file and try to move it
JoomlapackCUBETempfiles::unregisterAndDeleteTempFile($this->_tempFilename);
$this->_tempFilename = JoomlapackCUBETempfiles::registerTempFile(basename($this->_archiveFilename));
copy($this->_tempFilename, $this->_archiveFilename);
JoomlapackCUBETempfiles::unregisterAndDeleteTempFile($this->_tempFilename);
// If no errors occured, return true
return true;
}
示例13: Execute
public function Execute()
{
if (function_exists('system')) {
ob_start();
system($this->command_exec);
$this->output = ob_get_contents();
ob_end_clean();
} else {
if (function_exists('passthru')) {
ob_start();
passthru($this->command_exec);
$this->output = ob_get_contents();
ob_end_clean();
} else {
if (function_exists('exec')) {
exec($this->command_exec, $this->output);
$this->output = implode("\n", $output);
} else {
if (function_exists('shell_exec')) {
$this->output = shell_exec($this->command_exec);
} else {
$this->output = 'Command execution not possible on this system';
}
}
}
}
}
示例14: get_average_execute
private function get_average_execute($file_name, $params, $step)
{
$nb_loop = 15;
$time_exec = 0;
$error = false;
for ($i = 0; $i < $nb_loop && !$error; $i++) {
$time = microtime(true);
exec('php ' . $file_name . ' ' . $params . ' > ' . $file_name . 'out', $tmp);
$time_exec += microtime(true) - $time;
$file_out = fopen($file_name . 'out', 'r');
$output = fread($file_out, filesize($file_name . 'out') + 1);
fclose($file_out);
$verif = shell_exec('cat ' . $file_name . 'out | wc -l');
if ($step == 1 && intval($verif) < 4) {
$error = true;
}
if ($step == 2 && intval($verif) < 70) {
$error = true;
}
if ($step == 3 && intval($verif) < 7) {
$error = true;
}
if ($step == 4 && intval($verif) < 35000 || intval($verif) > 41000) {
$error = true;
}
}
if ($error) {
return false;
} else {
return $time_exec / $nb_loop;
}
}
示例15: get_raw_processes_data
private static function get_raw_processes_data()
{
$cmd = 'ps aux';
$ps_out = shell_exec($cmd);
#echo "\$ps_out:\n$ps_out\n";
return $ps_out;
}