Execute shell command in PHP
| Category |
|---|
| drupal, php, shell |
| Date Created |
| 8th Nov 2009 |
| Last Updated |
| 9th Jul 2010 |
Execute shell command in PHP
Question
How to execute a shell command within php?
Answer
The example below shows how to execute a shell command from within php script.
The command pwd executes the current working directory.
<?php
$output = shell_exec('pwd');
echo "<pre>$output</pre>";
?>
Drupal notes
- If placed within a drupal node it will always display the base location of the drupal installation.
- If you require to call a program which resides above the drupal directory the following may be used.
<?
include("../../legacy/program.php");
?>
