473,480 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

running shell command within php

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
3 10812
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7991
by: Hal Vaughan | last post by:
I need to be able to run external commands from within a Java program, on Linux and Windows (and eventually OSX). Under most circumstances there is no problem, but if the path I specify as part of...
9
1965
by: Erik Geiger | last post by:
Hi, sorry, my english ist not that got but I'll try. I have a running python script (capisuit incoming.py). This script shall start a linux shell script. If I start this script like...
1
536
by: Mike Kamzyuk | last post by:
Hello all. This topic has been covered on google groups before, but I couldn't find a good response. I have a shell command I wish to execute from c# (or vb or your favorite .net language). I...
2
7448
by: bbxrider | last post by:
for win2k adv server/iis5.0 trying to run an external program from my asp routine that has multiple parameters, see following set shell = server.createobject("wscript.shell") shell.Run...
8
1333
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
8
35023
by: zhiwei wang | last post by:
I remember that there is a function that could invoke shell command such as "rm" "cp", directly in .c file. But I could not recall its name, and I googled with nothing meaningful. I vaguely...
0
2161
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a...
5
5064
by: inetquestion | last post by:
I am looking for a web interface for shell commands or shell scripts. Does anyone know of any exexisting php scripts which would solve this requirement? PHP form accepts input from a user, then...
3
6713
by: Max Vit | last post by:
I have come across a strange issue whilst trying to use a shell command call from Access and have spent some time trying to figure this out but can't find the cause as yet. The issue is: I need...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6732
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4472
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.