Re: [PHP] exec and system do not work

[email protected] (Robert Cummings)
Newsgroups php.general
Organization InterJinn
Message-ID <[email protected]>
On 13-08-25 11:41 PM, Ethan Rosenberg wrote:
> Dear List -
>
> I'm lost on this one -
>
> This works -
>
> $out = system("ls -l ",$retvals);
> printf("%s", $out);
>
> This does -
>
> echo exec("ls -l");
>
> This does not -
>
> if( !file_exists("/var/www/orders.txt"));
> {
>      $out = system("touch /var/www/orders.txt", $ret);
>      $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");
> }
>
> Ethan

Hi Ethan,

Is there a reason you're using shell commands to achieve the following:

<?php

     $path = '/var/www/orders.txt';
     if( !file_exists( $path ) )
     {
         if( !touch( $path ) )
         {
             echo 'Failed to touch file into existence: '.$path."\n";
         }
         else
         {
             if( !chmod( $path, 0766 ) )
             {
                 echo 'Failed to update file permissions: '.$path."\n";
             }
         }
     }

?>

Also, why are you setting the executable bit on a text file? :)

Cheers,
Rob.
-- 
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.