1
2I'm not sure what shell you are going to get with this function, but you can find out like this:
3
4<?php
5$cmd = 'set';
6echo "<pre>".shell_exec($cmd)."</pre>";
7?>
8
9On my FreeBSD 6.1 box I get this:
10
11USER=root
12LD_LIBRARY_PATH=/usr/local/lib/apache2:
13HOME=/root
14PS1='$ '
15OPTIND=1
16PS2='> '
17LOGNAME=root
18PPID=88057
19PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
20SHELL=/bin/sh
21IFS='
22'
23
24Very 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:
25
26<?php
27$cmd = 'export PATH="/usr/local/bin/"; convert -scale 25%x25% file1.pdf[0] file2.png 2>&1';
28echo "<pre>".shell_exec($cmd)."</pre>";
29?>
30
31ALSO, note that shell_exec() does not grab STDERR, so use "2>&1" to redirect it to STDOUT and catch it.
32
1php php_file.php
2// or
3php php_file.php > result_file.txt // to display the result of echoes or dumps