Integrating Bash with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
james2010
Forum Newbie
Posts: 4
Joined: Thu Jan 28, 2010 7:47 am

Integrating Bash with PHP

Post by james2010 »

Hi, I'm running php 5.3 on windows. I've recently downloaded the GNU Bash shell for windows. I made an example bash file and can run it through the command prompt. I'm trying to get it to run through a web page using "shell_exec".

The instructions for installing bash tell me to add the bash.exe path to my classpath setting, create a home directory and then set the environmental variable HOME to point to it. I'm already lost at this point. Can someone tell me how you add bash.exe to my classpath setting and the proper way to create a home directory?

I know shell_exec works because I can call windows processing and it works just fine. For example

Code: Select all

 
$result = shell_exec('cmd version');
 
results in:

Code: Select all

 
Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Program Files\Apache Software Foundation\Apache2.2\htdocs>
 
Thanks

James
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Integrating Bash with PHP

Post by AbraCadaver »

You really shouldn't have to do either one of these. Maybe the home dir, but I don't think so. Just do it like this:

Code: Select all

$result = exec('x:/path/to/bash.exe x:/path/to/your/script.sh', $output);
It is going to be a pain to get shell_exec() to use bash on windows I think.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
james2010
Forum Newbie
Posts: 4
Joined: Thu Jan 28, 2010 7:47 am

Re: Integrating Bash with PHP

Post by james2010 »

Thanks!

Your correct, you don't need either. Your example worked great.

James
Post Reply