generaldarkness Posted December 10, 2007 Share Posted December 10, 2007 Having trouble with running php in a shell script. The command im trying to use is echo '<?php echo "test"; ?>' | php -q This simply returns nothing from the command line, ive tried path to php aswell and no joy. #!/usr/local/bin/php -q <?php echo "test"; ?>' Will work, so it looks like the cli is working but i cant execute it from within a shell script. php -v shows PHP 5.2.5 (cli) (built: Nov 22 2007 02:14:24) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies with the ionCube PHP Loader v3.1.32, Copyright (c) 2002-2007, by ionCube Ltd., and with Zend Extension Manager v1.2.0, Copyright (c) 2003-2007, by Zend Technologies with Zend Optimizer v3.3.0, Copyright (c) 1998-2007, by Zend Technologies was built with whm really cant work out how to get this working, anyone got any ideas? Thx in advance Quote Link to comment Share on other sites More sharing options...
zq29 Posted December 10, 2007 Share Posted December 10, 2007 The following works for me... php -r "echo 'Hello World';" Quote Link to comment Share on other sites More sharing options...
generaldarkness Posted December 10, 2007 Author Share Posted December 10, 2007 thx for the reply SemiApocalyptic , that also works for me fine. Trouble is i need to get it working from the following command as its part of a install script, so if it doesnt work at this point the rest of the install doesnt work properly. Heres the full section that it stops at. # make sure PHP is sane PHPTEST=`echo '<?php echo "test"; ?>' | php -q 2>&1` if [ "x$PHPTEST" != "xtest" ]; then echo "Your PHP CLI binary does not appear to be working correctly. Please" echo "correct this problem and then restart this installation script." exit 1 Quote Link to comment Share on other sites More sharing options...
generaldarkness Posted December 11, 2007 Author Share Posted December 11, 2007 Can anyone help?? Quote Link to comment Share on other sites More sharing options...
trq Posted December 11, 2007 Share Posted December 11, 2007 PHPTEST=$(/usr/bin/php -r 'echo "test";') if [ "$PHPTEST" != "test" ]; then echo "Your PHP CLI binary does not appear to be working correctly. Please" echo "correct this problem and then restart this installation script." exit 1 fi Of course, you would be much better of checking whereis to see if php exists somewhere else. Who says it must be in /usr/bin/php Quote Link to comment Share on other sites More sharing options...
generaldarkness Posted December 11, 2007 Author Share Posted December 11, 2007 Hey thorpe thanks for the reply, which php shows /usr/local/bin/php, but running this still returns nothing from the command line, plus i need to be able to find php by using the php command not the path to it. Do you think there must be something wrong with my php? and do you think a recompile would help?. Edit: after waking up i realised this was meant to return nothing from the command line, so it is working by using php aswell. So does this mean my php is working ok and do you know why it wouldnt work the other way as my install doesnt seem to be working properly when it gets stuck at this point of the script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.