473,545 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
+ 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 10830
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_functio ns.
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
7995
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 the command has any spaces in it, or an argument for the command is a path with a space in it, or if I redirect the output to a file with a space...
9
1969
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 os.system(/paht/to shellscipt.sh) the python scipt waits for the exit of the shell script and then goes on with the rest of the python script. How to start...
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 know the relevant class is System.Diagnostics.Process. The problem is that I don't know the name of the exe (or bat, or whatever) of the process. ...
2
7466
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 """f:\phsData\htmldoc\htmldoc.exe"" --webpage -f phsnew.pdf phsnew.htm" program either doesn't get invoked, or has an error, but since it has no error...
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 newsgroups I learned that there is a function in stdlib.h called system. int system(const char *command); First question, is the system command...
8
35031
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 remember it is like: foo("cp file1 file2"); it is that simple, but cant remember. Could anyone here give me a clue?
0
2167
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 command button in the application. So the code goes something like this: psiBat = New ProcessStartInfo(arrRun.Item(0)(1)) psiBat.WindowStyle =...
5
5070
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 passes these as arguments to a configurable shell script or OS command. I would like for the output generated from the shell script/command shall...
3
6724
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 to execute a command call from within Access to execute a batch file (sample.bat). To do this, we use the Shell function, something like: Shell...
0
7487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7934
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7446
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7778
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5349
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1908
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 we have to send another system
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.