Re: [PHP] Capturing System output

2006-08-15 Thread Richard Lynch
On Tue, August 15, 2006 9:19 am, Brad Bonkoski wrote:
> Had this problem in the past, and always programmed around it, but
> wondering if there is an easier way.
>
> Good Example:
> Creating a setup for connecting to a mysql database.  Want to do
> something simple to make sure they have entered a valid
> username/password for the database.
> So, the idea is something like:
> $rc = exec("mysql -u $user -p{$pass}", $output);
> The problem is one error, the stderr does not go to the output array,
> but rather to the screen.
>
> Previously I would redirect the stderr to a file, and then evaluate
> the
> contents of the file, but is there an easier way to get this into the
> PHP variable with no risk of having the output make it through to the
> screen?

In some OSes, in some shells, you can use:
mysql -u $user -p{$pass} 2>&1

The 2>&1 is special code for "redirect stdrrr (aka 2) to stdout (aka 2)"

Unless it's 2&>1 which I always forget which is which...

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Capturing System output

2006-08-15 Thread Ray Hauge
On Tuesday 15 August 2006 09:38, Brad Bonkoski wrote:
> Stut wrote:
> > Brad Bonkoski wrote:
> >> Had this problem in the past, and always programmed around it, but
> >> wondering if there is an easier way.
> >>
> >> Good Example:
> >> Creating a setup for connecting to a mysql database.  Want to do
> >> something simple to make sure they have entered a valid
> >> username/password for the database.
> >> So, the idea is something like:
> >> $rc = exec("mysql -u $user -p{$pass}", $output);
> >> The problem is one error, the stderr does not go to the output array,
> >> but rather to the screen.
> >>
> >> Previously I would redirect the stderr to a file, and then evaluate
> >> the contents of the file, but is there an easier way to get this into
> >> the PHP variable with no risk of having the output make it through to
> >> the screen?
> >
> > I may be missing something, but why in the name of all that is holy
> > would you want to shell out to try connecting to mysql? Why not use
> > mysql_connect and avoid the potentially massive security hole you're
> > building?
> >
> > -Stut
>
> Perhaps poor illustration of the question...the question being how to
> issue system like commands in PHP which would allow you to trap not only
> stdout, but also stderr.
> -Brad

Best example I found was:

$shell_return = shell_exec($shell_command." 2>&1");

that should redirect stderr to stdout and thus you'd get both.

-- 
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Capturing System output

2006-08-15 Thread Stut

Brad Bonkoski wrote:
Had this problem in the past, and always programmed around it, but 
wondering if there is an easier way.


Good Example:
Creating a setup for connecting to a mysql database.  Want to do 
something simple to make sure they have entered a valid 
username/password for the database.

So, the idea is something like:
$rc = exec("mysql -u $user -p{$pass}", $output);
The problem is one error, the stderr does not go to the output array, 
but rather to the screen.


Previously I would redirect the stderr to a file, and then evaluate 
the contents of the file, but is there an easier way to get this into 
the PHP variable with no risk of having the output make it through to 
the screen?


I may be missing something, but why in the name of all that is holy 
would you want to shell out to try connecting to mysql? Why not use 
mysql_connect and avoid the potentially massive security hole you're 
building?


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Capturing System output

2006-08-15 Thread KermodeBear
Hello,

If you are working on a Linux system, you can try appending:
2>&1
To the end of your command, so that you end up with:
Mysql -u $user -p{$pass} 2>&1

What this does is tell the shell to redirect anything from stderr to go
through stdout.

If you want to get -really- fancy you can use proc_open, which will give you
handles for the process' stdout, stderr, and stdin.

HTH,
K. Bear

> -Original Message-
> From: Brad Bonkoski [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, August 15, 2006 10:38 AM
> To: Stut
> Cc: PHP List
> Subject: Re: [PHP] Capturing System output
> 
> 
> 
> Stut wrote:
> > Brad Bonkoski wrote:
> >> Had this problem in the past, and always programmed around it, but 
> >> wondering if there is an easier way.
> >>
> >> Good Example:
> >> Creating a setup for connecting to a mysql database.  Want to do 
> >> something simple to make sure they have entered a valid 
> >> username/password for the database.
> >> So, the idea is something like:
> >> $rc = exec("mysql -u $user -p{$pass}", $output); The 
> problem is one 
> >> error, the stderr does not go to the output array, but 
> rather to the 
> >> screen.
> >>
> >> Previously I would redirect the stderr to a file, and then 
> evaluate 
> >> the contents of the file, but is there an easier way to 
> get this into 
> >> the PHP variable with no risk of having the output make it 
> through to 
> >> the screen?
> >
> > I may be missing something, but why in the name of all that is holy 
> > would you want to shell out to try connecting to mysql? Why not use 
> > mysql_connect and avoid the potentially massive security 
> hole you're 
> > building?
> >
> > -Stut
> >
> Perhaps poor illustration of the question...the question 
> being how to issue system like commands in PHP which would 
> allow you to trap not only stdout, but also stderr.
> -Brad
> 
> --
> PHP General Mailing List (http://www.php.net/) To 
> unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Capturing System output

2006-08-15 Thread Brad Bonkoski



Stut wrote:

Brad Bonkoski wrote:
Had this problem in the past, and always programmed around it, but 
wondering if there is an easier way.


Good Example:
Creating a setup for connecting to a mysql database.  Want to do 
something simple to make sure they have entered a valid 
username/password for the database.

So, the idea is something like:
$rc = exec("mysql -u $user -p{$pass}", $output);
The problem is one error, the stderr does not go to the output array, 
but rather to the screen.


Previously I would redirect the stderr to a file, and then evaluate 
the contents of the file, but is there an easier way to get this into 
the PHP variable with no risk of having the output make it through to 
the screen?


I may be missing something, but why in the name of all that is holy 
would you want to shell out to try connecting to mysql? Why not use 
mysql_connect and avoid the potentially massive security hole you're 
building?


-Stut

Perhaps poor illustration of the question...the question being how to 
issue system like commands in PHP which would allow you to trap not only 
stdout, but also stderr.

-Brad

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Capturing System output

2006-08-15 Thread Ray Hauge
On Tuesday 15 August 2006 09:19, Brad Bonkoski wrote:
> Hello All..
>
> Had this problem in the past, and always programmed around it, but
> wondering if there is an easier way.
>
> Good Example:
> Creating a setup for connecting to a mysql database.  Want to do
> something simple to make sure they have entered a valid
> username/password for the database.
> So, the idea is something like:
> $rc = exec("mysql -u $user -p{$pass}", $output);
> The problem is one error, the stderr does not go to the output array,
> but rather to the screen.
>
> Previously I would redirect the stderr to a file, and then evaluate the
> contents of the file, but is there an easier way to get this into the
> PHP variable with no risk of having the output make it through to the
> screen?
>
> Thanks
> -Brad

I'd take a look at shell_exec.  There'sa comment about capturing stderr.  I'm 
not sure if shell_exec captures stderr, but it should at least point you in 
the right direction.  Just do a search for stderr and you should find some 
good info.

-- 
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php