Re: [PHP] Interacting With Shell

2010-09-17 Thread Richard Quadling
On 17 September 2010 14:15, Floyd Resler  wrote:
> I need to run a Linux command from within PHP but the command has 
> interaction.  At one point I need to enter a password.  Is this type of 
> interaction possible inside a PHP script?
>
> Thanks!
> Floyd
>
>

Yes it is ... and it also works on Windows ...

This is PEAR's Console_CommandLine_Action_Password::_promptPassword() method.

private function _promptPassword()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
fwrite(STDOUT,
$this->parser->message_provider->get('PASSWORD_PROMPT_ECHO'));
@flock(STDIN, LOCK_EX);
$passwd = fgets(STDIN);
@flock(STDIN, LOCK_UN);
} else {
fwrite(STDOUT,
$this->parser->message_provider->get('PASSWORD_PROMPT'));
// disable echoing
system('stty -echo');
@flock(STDIN, LOCK_EX);
$passwd = fgets(STDIN);
@flock(STDIN, LOCK_UN);
system('stty echo');
}
return trim($passwd);
}

Essentially fgets(STDIN) is the key.

On windows you have to press enter. Even if you try using fgetc().


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



[PHP] Interacting With Shell

2010-09-17 Thread Floyd Resler
I need to run a Linux command from within PHP but the command has interaction.  
At one point I need to enter a password.  Is this type of interaction possible 
inside a PHP script?

Thanks!
Floyd



smime.p7s
Description: S/MIME cryptographic signature