Jump to content

Run a script file in php code????


noman

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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().

 

 

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.