You are here: Re: Exec() and 'keyboard' input « PHP Programming Language « IT news, forums, messages
Re: Exec() and 'keyboard' input

Posted by C. (http://symcbean.blogspot.com/) on 10/08/07 11:43

On 7 Oct, 22:20, "Janwillem Borleffs" <j...@jwscripts.com> wrote:
> > I can do system or exec("change-settings"); ok, but how do I 'enter'
> > the input from a php-script? The new-settings1 and 2 will be stored
> > in variables in PHP.
>
> Two possibilities:
>
> #1:
>
> <?php
>
> $buf = '';
> $fp = fopen('php://stdin', 'r');
> while (!feof($fp)) {
> $buf .= fgets($fp, 1024);
>
> }
> print "You wrote: $buf";
>
> ?>
>
> (when finished, exit with CRTL+Z+<ENTER>)
>
> #2
>
> <?php
>
> $buf = '';
> $fp = fopen('php://stdin', 'r');
> while (trim(($line = fgets($fp, 1024)))) {
> $buf .= $line;
>
> }
> print "You wrote: $buf";
>
> ?>
>
> (when finished, just hot <ENTER> twice)
>
> HTH;
> JW

This is for getting keyboard input into PHP not sending keyboard input
to the spawned process - a complete solution would use proc_open() to
be able to process stdout and stderr from the spawned process as well
as sending instructions, but if simplicity is required, then just
write directly to stdin:

$fp=popen("/path/to/change-settings", 'w');
if ($fp) {
fputs($fp,"new-setting 1\n");
fputs($fp,"new-setting 2\n");
fclose($fp);
}

Alternatively write the new setting to a file and redirect stdin for
the command to the file:

$outcome=`/path/to/change-settings <file_I_wrote`;


C.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация