As of PHP 4.3.0 you can use the proc_* functions (proc_open & proc_close in PHP 4.3.0+ and proc_get_status, proc_nice and proc_terminate as of PHP 5).

If you don't have access to that, you can use the following:
use shell_exec to create a process, and make it send all output to some temporary file. Then, instead of getting it directly, you just read the contents of that temporary file :)


eg:
$stream = fopen('cvs server .... > /tmp/cvsOutput', 'w+');
just read it from /tmp/cvsOutput, and write to the $stream :)

hope it helps,
- Tul

Joel Kitching wrote:
Hello, is it possible to open a stream in which I can write commands
and read output from them to a shell like bash?  I want to do this
because this program can not be completed with just a `backtick` or
shell_exec() command, as it's somewhat user-interactive.

As an example, let's say I want to get cdecl to explain to me what
"char *horse" means.  I would type:

# <i>cdecl</i>
Type `help' or `?' for help
cdecl> <i>explain char *horse</i>
declare horse as pointer to char
cdecl> <i>exit</i>

...where input is surrounded by <i>these</i>.  This would be difficult
or impossible to do with shell_exec, especially if halfway-through you
have to do some calculating before you can know what to ask cdecl
next.

So I want to know whether you can somehow open a stream to a shell,
and execute commands there.  Like...

$fp = fopen('/bin/bash', 'rw');
$output = fgets($fp);
fputs($fp, 'cdecl');
$output = fgets($fp);
$output = fgets($fp);
fputs($fp, 'explain char *horse');
$expl = fgets($fp);
/* Right now you could do some calculations and figure out what to do next. */
$output = fgets($fp);
fputs($fp, 'exit');
$output = fgets($fp);
fclose($fp);

Now this obviously wouldn't work, as it would overwrite the bash
executable if you had proper access, but it's just to get the idea
across.

So, does anyone know how I can do this?


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



Reply via email to