0

A few days ago I published this thread, and it was solved succesfully on Unix.

Now I moved to Windows and I have the same problem.

I need to execute a command from the web application. It must execute a .jar stored in the system. I looked on Google and found some changes that I needed to do.

The function to execute the command is:

<?php
if($_POST["name"] == "")
    echo "name is empty";
else{
    $path = $_POST["name"];
    //$command = 'DISPLAY=:0 java -jar '.$path'; -> Used in Unix
    //$command = 'java -jar ../../../../simulaciones/tanqueCalentamiento.jar';
        $command = 'java -jar ..\..\..\..\simulaciones\tanqueCalentamiento.jar';
    //system($command);
    exec($command);
}
?>

The comments are different options I have tried. $path is the argument, but decided to put directly the path, to clarify my question:

Do I need a kind of "trick" as I did for Unix?

3 Answers 3

2

The one I use:

function _exec($cmd)
{
   $WshShell = new COM("WScript.Shell");
   $oExec = $WshShell->Run($cmd, 0,false);
   error_log($cmd);
   return $oExec == 0 ? true : false;
}

/!\ If your application has an interface, and if you are using vista or 7, your server can't be run as a service!

Sign up to request clarification or add additional context in comments.

22 Comments

My applicacion has an interface and I am using 7... I used your function and it returns 1. As I don't understand very well your code, I don't know neither what it really means... Sorry, completely newbie in this field...
The application has probably been launched, but you can't see it. Which server are you using? apache, IIS?
@Blanca WScript.Shell provides direct access to the shell via COM, I have mentioned it previously here with links to the official docs which explain what it does/how it works.
Yes.. She is... she should start apache from the user, not from the session Console
and does Apache starts as a service? if yes, this could not work better... it must NOT start as a service as you have a GUI
|
0

You're just starting 'java'. That means that the Java executable (java.exe) must exist, and must be able to be executed. Since you don't specify a path, it must be in a directory that is in the %PATH% environment variable.

To test, simply start cmd and type java<enter>. If java gets executed, you'll know at least you'll have java installed and startable. If it doesn't, check if you have java and specify the correct path to the java executable.

You can also run the .jar from the command line to see if it works. If it works like this, it is likely to work in PHP too.

1 Comment

I have jaava installed, and if I run thee same command it runs with no problem. Then I guess, the problemm must be in another place...
0

In windows vista, 7 (I don't know if in others too), there is a problemm with xampp.

The apache does not stop, doesn't matter what you do, even switch the computer off. At least for me, the solution was:

  1. Uninstall xamp and reinistall it.
  2. Start/stop it always as administrator:

    path\xampp\xampp_start
    path\xampp\xampp_stop

Right click: run as administrator.

In this way apache is finished properly, and I can run my command with no probleems anymore

I hope this helps http://drupal.org/node/224342

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.