PHP exec function

I want to start a java program (.jar file) with a php script got this script in my www folder (wampserver) and want to start file.jar(that is also in my www folder.) How can i do this already looked up at google but this code always fail. So somebody any idea. (the program need to open at the foreground.)

grtz
Comments
11
Assuming your webserver machine has jre installed, you can use something like this "java -jar myJar.jar" or "javaw -jar myJar.jar", depends on if you want console or not. Just be sure you add correct path to jar file and your jre bin folder is in path variable to be able to use shortcut (if you are not sure and you know fullpath to java.exe/javaw.exe, you can do so to be sure).
<?php
exec('java -jar jar.jar', $output);
print_r($output);
?>
but now for example i just want to open notepad (nohing to do with the jar ( it ain't working with the jar but i just want to run an othe program maybe i understand it with notepad) )

and i tried this:

<body>
<?php
exec('C:\WINDOWS\System32\notepad.exe', $output);
print_r($output);
?>

</body>

i tried this on 127.0.0.1/test.php
and my browser keeps loading so nothing happend, also tried this without the $output but same result.
Parent
That will not work. The server will just open notepad (in the background) and wait. So your browser is waiting for the server which is waiting for notepad to do something and close.
Anything you execute using exec must terminate.
Parent
is there an function what can do that? so put notepad on foreground?
Parent
Try
system('start notepad');
Parent
this didn't worked for me
Parent
<?php
$command = "c:\\Windows\\notepad.exe";
exec($command);
?>
it works like this now the only problem is it wil run as a proces on the background and the User is SYSTEM any idea how to change this?
Parent
Why not use .bat file?
E: echo exec('file.jar');
why does a java file you are running on a webserver need to open in the foreground?
actually the final plan is: im somewhere on the internet i go to my page log in on my website there i got a button light on light out in the room were my server is hosted, (written in c, code) so i need to be able to execute that C program (that java file was just for example) now the reason for that it runs on the foreground if just for the visual stuf. so i can see that it works..
Parent
Back to top