Professional Web Applications Themes

running shell command within php - PHP Development

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. Code: if(exec("/bin/cp -f /home/web/public/min-pizza/master/ /home/web/public/min-pizza/$postnr/$folder/") == TRUE) echo "... masterfiles copied ..."; $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...

  1. #1

    Default 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.

    Code:
    if(exec("/bin/cp -f /home/web/public/min-pizza/master/
    /home/web/public/min-pizza/$postnr/$folder/") == TRUE)
    echo "... masterfiles copied ...";
    $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
    Andreas Paasch Guest

  2. #2

    Default Re: running shell command within php

    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.
    >
    >
    Code:
    > if(exec("/bin/cp -f /home/web/public/min-pizza/master/
    >                 /home/web/public/min-pizza/$postnr/$folder/") == TRUE)
    >         echo "... masterfiles copied ...";
    >
    >
    > $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

    vAm Guest

  3. #3

    Default Re: running shell command within php

    Andreas Paasch <AndreasPaasch.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
    [url]http://www.fuhr.org/~mfuhr/[/url]
    Michael Fuhr Guest

  4. #4

    Default Re: running shell command within php

    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.
    >
    >
    Code:
    > if(exec("/bin/cp -f /home/web/public/min-pizza/master/
    >                 /home/web/public/min-pizza/$postnr/$folder/") == TRUE)
    >         echo "... masterfiles copied ...";
    >
    >
    > $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
    Andreas Paasch Guest

Similar Threads

  1. Shell command from within Adobe Professional, copy and delete file
    By David_Gottholm@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 14
    Last Post: March 17th, 03:35 PM
  2. formatting output of `ls -l` shell command
    By lecichy in forum PHP Development
    Replies: 5
    Last Post: October 16th, 02:05 AM
  3. Using 'Shell' command in code.
    By Alex Mirzayanov in forum ASP.NET Web Services
    Replies: 1
    Last Post: September 19th, 08:54 AM
  4. Replies: 1
    Last Post: August 19th, 02:26 AM
  5. executing a shell command within a function
    By Svlyp in forum PHP Development
    Replies: 0
    Last Post: August 16th, 12:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139