By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,530 Members | 880 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,530 IT Pros & Developers. It's quick & easy.

running shell command within php

P: n/a
According to the manual for PHP, I should be able to run a shell command
within php.

I'm trying to copy some php files from one location to another one using
exec() but fail.

Expand|Select|Wrap|Line Numbers
  1. if(exec("/bin/cp -f /home/web/public/min-pizza/master/
  2. /home/web/public/min-pizza/$postnr/$folder/") == TRUE)
  3. echo "... masterfiles copied ...";
  4.  
$postnr = 2720
$folder = 38747117-robertos

They are created dynamically and must stay as they are, it's a standard
format for creating folders and consequently copying files.

But can't do it ... I've read and read, found no solution so far.

Any help is highly welcome.
--
Registeret Linux user #292411
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
vAm
Andreas Paasch wrote:
According to the manual for PHP, I should be able to run a shell command
within php.

I'm trying to copy some php files from one location to another one using
exec() but fail.

Expand|Select|Wrap|Line Numbers
  1.  if(exec("/bin/cp -f /home/web/public/min-pizza/master/
  2.                  /home/web/public/min-pizza/$postnr/$folder/") == TRUE)
  3.          echo "... masterfiles copied ...";
  4.  

$postnr = 2720
$folder = 38747117-robertos

They are created dynamically and must stay as they are, it's a standard
format for creating folders and consequently copying files.

But can't do it ... I've read and read, found no solution so far.

Any help is highly welcome.


I'm a newbie to PHP. Well, did you try the function system()? Same
syntax as in C.

vAm

Jul 17 '05 #2

P: n/a
Andreas Paasch <An*****@Paasch.Net> writes:
According to the manual for PHP, I should be able to run a shell command
within php.
Correct, but this ability can be restricted by settings in php.ini,
such as safe_mode, safe_mode_exec_dir, and disable_functions.
I'm trying to copy some php files from one location to another one using
exec() but fail.

if(exec("/bin/cp -f /home/web/public/min-pizza/master/
/home/web/public/min-pizza/$postnr/$folder/") == TRUE)
echo "... masterfiles copied ...";


It looks like you're trying to copy directories, and on most Unix-like
systems you need to give cp a recursive option (-r or -R) to do
that. Read the manual page for cp and make sure your cp command
works from the shell prompt before trying to make it work in PHP.

Also, exec() returns the last line of the command's output, not a
status indicating success or failure. A successful cp command
doesn't usually produce any output, so exec()'s return value will
be an empty string, which evaluates to FALSE. If you want to get
the command's exit status then use the three-argument form of exec(),
which stores the status in the third argument. The Unix convention
is that an exit status of 0 means success and anything else means
failure, so be sure to take that into account.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 17 '05 #3

P: n/a
Andreas Paasch wrote:
According to the manual for PHP, I should be able to run a shell command
within php.

I'm trying to copy some php files from one location to another one using
exec() but fail.

Expand|Select|Wrap|Line Numbers
  1.  if(exec("/bin/cp -f /home/web/public/min-pizza/master/
  2.                  /home/web/public/min-pizza/$postnr/$folder/") == TRUE)
  3.          echo "... masterfiles copied ...";
  4.  

$postnr = 2720
$folder = 38747117-robertos

They are created dynamically and must stay as they are, it's a standard
format for creating folders and consequently copying files.

But can't do it ... I've read and read, found no solution so far.

Any help is highly welcome.

Actually, I stumpled over the obvious - PHP function copy().
Didn't even get that to work, however in the notes a nice little function
was written so I tested that - works like a charm now.

I don't have any PHP limitations set, so that's not the issue, I have tried
system() too, to no avail. It must somehow be related to my syntaxing.

Now, about the recursive option for copy, it's only needed if I want
subdirectories copied, which isn't the case, I only wanted all files from
/master/ to be copied to the newly created folder.

But, the function mentioned works so for now I go on with my coding, my
optimizing it all is a later chapter ....

Thanks anyways, always helps to get some new eyes on problems.

/Andreas

--
Registeret Linux user #292411
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.