Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

shell_exec

(PHP 4, PHP 5)

shell_exec -- Execute command via shell and return the complete output as a string

Описание

string shell_exec ( string cmd )

This function is identical to the backtick operator.

Список параметров

cmd

The command that will be executed.

Возвращаемые значения

The output from the executed command.

Примеры

Пример 1. A shell_exec() example

<?php
$output
= shell_exec('ls -lart');
echo
"<pre>$output</pre>";
?>

Примечания

Замечание: Эта функция недоступна в безопасном режиме.

Смотрите также

exec()
escapeshellcmd()



system> <proc_terminate
Last updated: Sat, 27 Jan 2007
 
add a note add a note User Contributed Notes
shell_exec
kamermans at teratechnologies dot net
15-Oct-2007 08:01
I'm not sure what shell you are going to get with this function, but you can find out like this:

<?php
$cmd
= 'set';
echo
"<pre>".shell_exec($cmd)."</pre>";
?>

On my FreeBSD 6.1 box I get this:

USER=root
LD_LIBRARY_PATH=/usr/local/lib/apache2:
HOME=/root
PS1='$ '
OPTIND=1
PS2='> '
LOGNAME=root
PPID=88057
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
SHELL=/bin/sh
IFS='    
'

Very interesting.  Note that the PATH may not be as complete as you need.  I wanted to run Ghostscript via ImageMagik's "convert" and ended up having to add my path before running the command:

<?php
$cmd
= 'export PATH="/usr/local/bin/"; convert -scale 25%x25% file1.pdf[0] file2.png 2>&1';
echo
"<pre>".shell_exec($cmd)."</pre>";
?>

ALSO, note that shell_exec() does not grab STDERR, so use "2>&1" to redirect it to STDOUT and catch it.
eric dot peyremorte at iut-valence dot fr
05-Oct-2007 02:01
I had trouble with accented caracters and shell_exec.

ex :

Executing this command from shell :

/usr/bin/smbclient '//BREZEME/peyremor' -c 'dir' -U 'peyremor%*********' -d 0 -W 'ADMINISTRATIF' -O 'TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192' -b 1200 -N 2>&1

gave me that :

Vid
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com
Z058440144362 Z348613067571