Forum Moderators: coopster

Message Too Old, No Replies

exec() and system() problems

trying to execute a shell script with php

         

erikcw

10:15 pm on Nov 9, 2005 (gmt 0)

10+ Year Member



Hi all,

I am trying to use php's exec() or system() to execute a shell script that I wrote.

exec and system() work fine with a simple command like ls, but nothing happens when I point it at the shell script.

The shell script works fine from my shell login. Can't figure out what tho problem is. Is php just incapable of running shell scripts?

Thanks for your help!

Erik

jatar_k

10:24 pm on Nov 9, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I have had problems with this as well, not really a huge fan of system or exec anyway but they are frustrating when I absolutely need to use them.

is there maybe another approach to having to exec the script?

have you tried using the full command that you execute from the command line?

erikcw

10:47 pm on Nov 9, 2005 (gmt 0)

10+ Year Member



I changed it to the full cammand and it started working.

Now a followup question. Which should I use? exec or system? Or does it matter?

Many thanks!
Erik

jatar_k

10:52 pm on Nov 9, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



exec
Return Values

The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.

To get the output of the executed command, be sure to set and use the output parameter.

system

system() is just like the C version of the function in that it executes the given command and outputs the result.

The system() call also tries to automatically flush the web server's output buffer after each line of output if PHP is running as a server module.

Return Values

Returns the last line of the command output on success, and FALSE on failure.

passthru

The passthru() function is similar to the exec() function in that it executes a command. This function should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser. A common use for this is to execute something like the pbmplus utilities that can output an image stream directly. By setting the Content-type to image/gif and then calling a pbmplus program to output a gif, you can create PHP scripts that output images directly.

which one? I don't know ;)

erikcw

11:07 pm on Nov 9, 2005 (gmt 0)

10+ Year Member



For my purpose it looks like system is the best match. Thanks for your help!