Re: exec and system do not work
| From: | Ethan Rosenberg, PhD | Date: | Tue, 27 Aug 2013 00:32:33 +0000 |
| Subject: | Re: exec and system do not work | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-321981@lists.php.net to get a copy of this message | ||
Ethan Rosenberg, PhD
/Pres/CEO/
*Hygeia Biomedical Research, Inc*
2 Cameo Ridge Road
Monsey, NY 10952
T: 845 352-3908
F: 845 352-7566
erosenberg@hygeiabiomedical.com
On 08/26/2013 07:33 PM, David Robley wrote:
Ethan Rosenberg wrote:David - touch returned 1 /chmod returned 1 rosenberg:/var/www# ls orders.txt ls: cannot access orders.txt: No such file or directory rosenberg:/var# ls -ld www drwxr-xr-x 37 ethan ethan 20480 Aug 26 20:15 www TIA EthanOn 08/26/2013 11:36 AM, marco@behnke.biz wrote:Please show the output of the directory listing. Please us "ls -la"Tamara -Tamara Temple <tamouse.lists@gmail.com> hat am 26. August 2013 um 08:33 geschrieben: On Aug 25, 2013, at 10:41 PM, Ethan Rosenberg <erosenberg@hygeiabiomedical.com> wrote:Please show the output of the directory listing. Please us "ls -la"Dear List - I'm lost on this one - This works - $out = system("ls -l ",$retvals); printf("%s", $out); This does - echo exec("ls -l");Maybe you don't have write permissions on the folder?This does not - if( !file_exists("/var/www/orders.txt")); {$out = system("touch /var/www/orders.txt", $ret);-- Marco Behnke Dipl. Informatiker (FH), SAE Audio Engineer Diploma Zend Certified Engineer PHP 5.3 Tel.: 0174 / 9722336 e-Mail: marco@behnke.biz Softwaretechnik Behnke Heinrich-Heine-Str. 7D 21218 Seevetal http://www.behnke.bizWhen you say "does not work", can you show what is actually not working? I believe the exec and system functions are likely working just fine, but that the commands you've passed to them may not be.$out2 = system("chmod 766 /var/www/orders.txt", $ret); echo 'file2<br />'; echo file_exists("/var/www/orders.txt");} and this does not - if( !file_exists("/var/www/orders.txt")); {exec("touch /var/www/orders.txt"); exec("chmod 766 /var/www/orders.txt"); echo 'file2<br />'; echo file_exists("/var/www/orders.txt");} Ethanecho exec('ls -la orders.txt'); -rw-rw-rw- 1 ethan ethan 43 Aug 25 23:50 orders.txt Maybe you don't have write permissions on the folder? If I perform the touch and chmod from the command line, everything works.Note that touch and chmod don't return any output, so echoing the result of a system call for those commands will give an empty string. You should be checking the values of $ret for each execution of system to see whether the command was successful or not - the return status of the executed command will be written to this variable. I'd guess that touch is returning 13 - permission denied. if( !file_exists("/var/www/orders.txt")) { system("touch /var/www/orders.txt", $ret1); echo 'touch returned '.$ret1.'<br> /'; system("chmod 766 /var/www/orders.txt", $ret2); echo 'chmod returned ' .$ret2.'<br> /'; echo 'file2<br />'; echo file_exists("/var/www/orders.txt"); } Check the permissions for directory /var/www; you'll probably find it is writable by the user you log on as, but not by the user that apache/php runs as, which is often www - a user with limited privileges. As other(s) have pointed out, there are php functions to do what you want without introducing the possible insecurities involved with system et al.working? IWhen you say "does not work", can you show what is actually notbut thatbelieve the exec and system functions are likely working just fine,Here are my commands. if( !file_exists("/var/www/orders.txt")); { echo system("touch /var/www/orders.txt", $ret); echo system("chmod 766 /var/www/orders.txt", $ret); echo 'file2<br />'; echo file_exists("/var/www/orders.txt"); } If I now try a ls from the command line, the return is cannot access /var/www/orders.txt: No such file or directory The ls -la works because the file was created from the command line. TIA Ethanthe commands you've passed to them may not be.