noman Posted May 22, 2009 Share Posted May 22, 2009 Hi all Am new to php, here's what am stuck at: I have a simple executable script file, lets say XYZ, for linux which needs two arguments (a & b) to be passed while executing. This script also calls another file which lies in the same folder. So this thing works perfect if I run script XYZ separately from the command prompt: root@server# XYZ a b All I need to do is to call this script XYZ inside php code. I've tried exec(), shell_exec(), system() but no result. these fundtions are working fine if I try to run basic commands like "ls -l" etc. Am working on Centos 5.2, tried changing the ownership of script files, permission in files but no use. ANY IDEA......???? thanks Noman Quote Link to comment https://forums.phpfreaks.com/topic/159320-run-a-script-file-in-php-code/ Share on other sites More sharing options...
MadTechie Posted May 22, 2009 Share Posted May 22, 2009 have you tried the pull path to the XYZ ? Quote Link to comment https://forums.phpfreaks.com/topic/159320-run-a-script-file-in-php-code/#findComment-840280 Share on other sites More sharing options...
anupamsaha Posted May 23, 2009 Share Posted May 23, 2009 Yes, check with full path. If it si not working, do the following: 1. Check if XYZ has the execution permission. 2. Check the owner of the command XYZ in your Linux system. Also, check the user running PHP (usually apache or www). If you see that the owner of XYZ is not the PHP user, change the owner to PHP user. Hope, this will help. Quote Link to comment https://forums.phpfreaks.com/topic/159320-run-a-script-file-in-php-code/#findComment-840517 Share on other sites More sharing options...
noman Posted May 24, 2009 Author Share Posted May 24, 2009 thanks for replying friends. but I have tried all these options. I changed the ownership of the XYZ to the user "apache". tried with the absolute path. the file is executable. is there any option in php function to specify the shell prompt along with the command string to run? I tried with the following different methods: $last_line = system('./XYZ', $returnval); or $command = "/var/www/html/XYZ"; $last_line = system($command, $retval); same case with exec() and shell_exec(). Quote Link to comment https://forums.phpfreaks.com/topic/159320-run-a-script-file-in-php-code/#findComment-841414 Share on other sites More sharing options...
MadTechie Posted May 24, 2009 Share Posted May 24, 2009 What do the error logs say ? for that matter whats echo $last_line; say Quote Link to comment https://forums.phpfreaks.com/topic/159320-run-a-script-file-in-php-code/#findComment-841416 Share on other sites More sharing options...
noman Posted May 24, 2009 Author Share Posted May 24, 2009 echo $last_line; doesnt show anything on the page. If I run that script separately at the shell prompt, it shud say sth like: "server reload successful" coz I reload a service in the script. If I try to run the commands like "ls -l" , the echo $last_line return the directory listing displayed on the page. Quote Link to comment https://forums.phpfreaks.com/topic/159320-run-a-script-file-in-php-code/#findComment-841419 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.