bash: passing output from one program to another

sometimes you want to be able to pass output from one program to another, say from bash to php. There is a neat trick to do it. In php, we execute the bash script restartapache.

$command="/usr/local/bin/restartapache {$_GET['server']}"; 
exec($command, $output); foreach ($output as $v) 
{ echo "$v <br/>"; } 

then in the bash, we write the output to a file. cat the file, then remove it.

# $Id$
# restart apache in a server
# bernard - 29 Jan 2009

name=`basename $0`
if [ $# != 1 ]
  cat <&1 /tmp/$$
cat /tmp/$$
rm /tmp/$$
exit 0;

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.