From: Floyd Resler on 17 Sep 2010 09:15 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
From: Richard Quadling on 17 Sep 2010 10:21 On 17 September 2010 14:15, Floyd Resler <fresler(a)adex-intl.com> 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
|
Pages: 1 Prev: Randomly duplicated Session Id between hosts Next: Install library |