liangzan
liangzan

Reputation: 6904

Cannot run shell function using PHP

I encountered some problems with the shell function in php. I want to execute a java program on the server by running a php function on a php webpage.

The java program writes some chars to a local file on the server.

test.php

<?php

   $WshShell = new COM("WScript.Shell");
   $cmd = '  "C:\\Program Files\\Java\\jdk1.6.0_14\\bin\\java" Importer 1 2 updated.txt 7';

   $WshShell->exec($cmd);
   echo "okay";
?>

When test.php is executed via command line on the server,

c:\php test.php

the java program runs.

However, if I executed it through web browser, the Java program is not called.

http://127.0.0.1/test.php

Is it because the Apache user is not allowed to use the command line functionality on windows?

System configuration:

Microsoft windows XP, Professional X64 edition, Version 2003, service pack 2 PHP version: 5.2.6.6 Apache 2.2 IIS 6

Upvotes: 1

Views: 751

Answers (4)

user149242
user149242

Reputation:

i found the solution here

Calling MySQL exe using PHP exec doesn't work

it is not the OS problem, but "quotes" problem.

Upvotes: 1

Nicolas
Nicolas

Reputation: 2186

Your problem could be due to PHP running with Apache under "safe_mode"...You can check this in your php.ini file.

Upvotes: 0

Qrilka
Qrilka

Reputation: 612

Why don't you use ordinary PHP 'exec' function?

Upvotes: 2

Peter
Peter

Reputation: 5798

What error do you got ?

Not really knowing php i do however have a question: You dont fully qualify the file that the Java program needs to update, you sure its not written but under some directory where your php server is installed,

Upvotes: 0

Related Questions