Page 1 of 1

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

Posted: Sat Apr 01, 2006 12:54 am
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.

Posted: Sat Apr 01, 2006 12:56 am
by s.dot
exec() maybe

Posted: Sat Apr 01, 2006 2:39 am
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"`;

use shell_exec to execute in shell

Posted: Sun Apr 02, 2006 1:32 am
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