views:

18

answers:

2

Hi Folks,

I wish to create a shell "Menu"

Instead of using bash for my script, I wish to use PHP. Is it possible to run an external program using php, that will interact with the user?

For example, let's say I wanted the php script to run /bin/bash (Just an example), but then when exiting bash, got back to the start of the script (i.e. display the menu again)

Thanks

A: 

Yes.

See:

Specifically:

proc_open('/bin/bash', array(STDIN, STDOUT, STDERR), $a = array());
Sjoerd
And all those allow interaction with the user instead of just running in the "background"?
jtnire
Edited to include an example.
Sjoerd
Thanks for that. What is the best way to supress any error messages (i.e. not showing them to the user)? Infact, it would be cool if the errors could be sent to an email address...
jtnire
For PHP errors set display_errors, for command errors use something else than STDERR in the array to proc_open.
Sjoerd
A: 

PHP can be used to create your so called "menu" program just like any other programming languages (eg Python/Perl etc). And unless its absolutely necessary, maybe you are calling a proprietary application, PHP has its own functions and modules to interact with the OS. For example, if you want to move/copy files, you can use functions such as rename(), copy() etc. Please read the PHP manual for more. Of course, if you really want to call external program from PHP, you can use exec() or shell_exec() among a few. Check the manual.

ghostdog74
Thanks for the tip on PHP's built in functions, however I wish to run "xm console x" to get to the console of a Xen DomU. If only PHP had this build in ;) !
jtnire