php-general Digest 26 Aug 2013 18:41:27 -0000 Issue 8345

Topics (messages 321966 through 321970):

Re: exec and system do not work
        321966 by: Sorin Badea
        321967 by: Robert Cummings
        321968 by: Tamara Temple
        321969 by: marco.behnke.biz
        321970 by: Ethan Rosenberg

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
*/var/www* is usually under *www* user. It may be a permissions problem.


On Mon, Aug 26, 2013 at 6:41 AM, Ethan Rosenberg <
erosenb...@hygeiabiomedical.com> 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Sorin Badea - Software Engineer

--- End Message ---
--- Begin Message ---
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.

--- End Message ---
--- Begin Message ---
On Aug 25, 2013, at 10:41 PM, Ethan Rosenberg <erosenb...@hygeiabiomedical.com> 
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
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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



--- End Message ---
--- Begin Message ---

> Tamara Temple <tamouse.li...@gmail.com> hat am 26. August 2013 um 08:33
> geschrieben:
>
>
>
> On Aug 25, 2013, at 10:41 PM, Ethan Rosenberg
> <erosenb...@hygeiabiomedical.com> 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");

Please show the output of the directory listing.
Please us "ls -la"

> >
> > This does not -
> >
> > if( !file_exists("/var/www/orders.txt"));
> > {
> >   $out = system("touch /var/www/orders.txt", $ret);

Maybe you don't have write permissions on the folder?

> >   $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
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
> When 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.
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

--- End Message ---
--- Begin Message ---

On 08/26/2013 11:36 AM, ma...@behnke.biz wrote:


Tamara Temple <tamouse.li...@gmail.com> hat am 26. August 2013 um 08:33
geschrieben:



On Aug 25, 2013, at 10:41 PM, Ethan Rosenberg
<erosenb...@hygeiabiomedical.com> 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");

Please show the output of the directory listing.
Please us "ls -la"


This does not -

if( !file_exists("/var/www/orders.txt"));
{
    $out = system("touch /var/www/orders.txt", $ret);

Maybe you don't have write permissions on the folder?

    $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



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



--
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz


Tamara -

> Please show the output of the directory listing.
> Please us "ls -la"

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


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

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

Ethan






--- End Message ---

Reply via email to