How to run a shell script in PHP(windows) URGENT!!!

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
uday123
Forum Newbie
Posts: 3
Joined: Sat Mar 25, 2006 8:44 am

How to run a shell script in PHP(windows) URGENT!!!

Post by uday123 »

Hi all,

I am using PHP in Windows XP.I want to run a shell script which generates an output file, using System function.How can I implement it?

I have tried in the following way(And open the php page using IE.).
for example:
system('echo "I like PHP" > output' ,$retval);
It is not creating any file.
But if i do like " system('echo "I like PHP"',$retval); " then it is printing fine on IE.

Can you please guide me.

Thanks in advance,
Uday.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

exec() maybe
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I'm aware of the fact that php - cmd.exe interop isn't very clear..

According to Windows cmd specifications the quotes are needed if one of the special characters is present in the command line.
The special characters that require quotes are: <space>&()[]{}^=;!'+,`~

Two sets of quotes are needed. Like this:

$result = `""c:\\program files\\some program\\prog.exe" "filename""`;

This won't work:

$result = `"c:\\program files\\some program\\prog.exe" "filename"`;
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

use shell_exec to execute in shell

Post by dibyendrah »

use the shell_exec to execute the process in the shell.

in linux,

Code: Select all

$output_from_proc = shell_exec("/path/to/command");
in windows,

Code: Select all

$output_from_proc = shell_exec("Drive_Letter:\\PATH\\TO\\Program.exe");
I haven't tested in windows, but this might be the correct syntax.

Dibyendra
Post Reply