Re: Two technical questions
| From: | James Lyon | Date: | Fri, 02 Jun 2000 10:37:53 +0000 |
| Subject: | Re: Two technical questions | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-899@lists.php.net to get a copy of this message | ||
> > Is it possible to execute a program from withing PHP and interact with it via
> > stdin/stdout? I have an external program which handles some security aspects
> > and need to feed it username/password via its stdin.
>
> Hmm, popen will allow you to open a process and either write to stdin,
> or read from stdin. You could do a hack like this:
>
> $tempfile = tempnam("./tmp/","temp");
> $fp = fopen($tempfile,"w");
> fputs($fp,"This is cool\n");
> fputs($fp,"This is a test\n");
> fputs($fp,"This is not a test\n");
> fclose($fp);
> $fp = popen("/bin/grep test < ".$tempfile,"r");
> fpassthru($fp);
> unlink($tempfile);
This doesn't scale well, though, does it? Actually Linux/Unix will cope rather
better than MS-Windows I believe with the above solution, so for moderate loads
perhaps it's the way to solve it.
I've had problems with stdin and stdout, too, but I've only got answers to date
that are in the manual ... i.e. the bits I can't find how to do remain unresolved!
As it is I've taken other approaches and much of the help I had has guided me to
alternative solutions.
So, my answer to the above question would be to try to find a way whereby you don't
need programmatic access to *both* stdin and stdout of the program you're calling.
How about a tiny wrapper (shell script, perl or C) that took the username /
password as arguments and sent them to the called external via stdin and allowed
the stdout to flow back in the normal way?