cps13 Posted December 14, 2011 Share Posted December 14, 2011 I have the following php code: <?php exec('java -jar d:\java\Test.jar'); ?> Is there a way to execute that jar without leaving the webpage? I'm trying to have an image you click on the executes a jar on the server, so I tried that. When I do action, it goes to the webpage localhost/Test.php, I want it to stay at local host, but still execute the jar. I tried jquery like this: <html> <head> <script src="http://code.jquery.com/jquery-lates… </head> <body> <img src="Test.png"> <script> $("img"").click(functions () { $.get("Test.php"); }); }); </script> </body> </html> But it doesn't click me an option to click. Some help? Quote Link to comment https://forums.phpfreaks.com/topic/253184-how-to-run-php-from-html/ Share on other sites More sharing options...
requinix Posted December 14, 2011 Share Posted December 14, 2011 I'm fairly sure that's not the actual code you tried. What is the real version you have? Quote Link to comment https://forums.phpfreaks.com/topic/253184-how-to-run-php-from-html/#findComment-1297975 Share on other sites More sharing options...
cps13 Posted December 15, 2011 Author Share Posted December 15, 2011 I realized there is a few errors. I changed them and here is my full code: <html> <head> <script src="jquery.js"></script> </head> <body> <div id="a"> <img src="test.png" /> </div> <script> $('#a').click(function() { $.get("test.php"); }); </script> </body> </html> That is the full html. The full php is: <?php exec('java -jar d:\java\Mainonoff.jar'); ?> The full .java file is: import parport.ParallelPort; class Mainonoff { public static void main ( string []args ) { int rByte = 0; int bByte=0; int relay5 = 0x0010; ParallelPort lpt1 = new ParallelPort(0x378); rByte = lpt1.readOneByte(0x378); if ((rByte & relay5) == 16) lpt1.write(rByte-16); } else { lpt1.write(rByte+16); } } } I don't see why the php/java code matter as if i go to command prompt and do php d:\java\test.php, It does exactly what I want it to do. My goal with this is to run the jar on the server by clicking an image on the webpage and not leaving the webpage. This is 100% the full code. Quote Link to comment https://forums.phpfreaks.com/topic/253184-how-to-run-php-from-html/#findComment-1297990 Share on other sites More sharing options...
gizmola Posted December 15, 2011 Share Posted December 15, 2011 Try in your exec call, passing the full path to the java program. Quote Link to comment https://forums.phpfreaks.com/topic/253184-how-to-run-php-from-html/#findComment-1297992 Share on other sites More sharing options...
cps13 Posted December 15, 2011 Author Share Posted December 15, 2011 I can execute the php file with no problems. My issue is onclick getting it to work. I think it's because it doesn't think of the $.get php as a functions Quote Link to comment https://forums.phpfreaks.com/topic/253184-how-to-run-php-from-html/#findComment-1297994 Share on other sites More sharing options...
gizmola Posted December 15, 2011 Share Posted December 15, 2011 No I'm saying that this call: exec('java -jar d:\java\Test.jar'); Probably needs to be exec('/path/to/java -jar d:\java\Test.jar'); You can use firebug to see if the jquery.get() is working or not. Quote Link to comment https://forums.phpfreaks.com/topic/253184-how-to-run-php-from-html/#findComment-1298005 Share on other sites More sharing options...
cps13 Posted December 15, 2011 Author Share Posted December 15, 2011 If I can run the php fine from cmd why would it matter? Sorry, I've never really done this before, and my issue is either 1. clicking the image does nothing or 2. if it does work I get no permission to view <?php exec('java -jar d:\java\Mainonoff.jar');?> Quote Link to comment https://forums.phpfreaks.com/topic/253184-how-to-run-php-from-html/#findComment-1298007 Share on other sites More sharing options...
gizmola Posted December 15, 2011 Share Posted December 15, 2011 If I can run the php fine from cmd why would it matter? Sorry, I've never really done this before, and my issue is either 1. clicking the image does nothing or 2. if it does work I get no permission to view <?php exec('java -jar d:\java\Mainonoff.jar');?> Yes, it matters, because what works from the command line doesn't necessarily work from the browser, as depending on how things have been setup, the environment of the two -- CLI (php.exe) and php as an apache module are different. As an apache module php runs as the apache configured user, often with an environement that has a minimal or empty path environment variable associated with it. Quote Link to comment https://forums.phpfreaks.com/topic/253184-how-to-run-php-from-html/#findComment-1298017 Share on other sites More sharing options...
cps13 Posted December 15, 2011 Author Share Posted December 15, 2011 I got it to work. Didn't modify php file, I added a document ready and some other things Quote Link to comment https://forums.phpfreaks.com/topic/253184-how-to-run-php-from-html/#findComment-1298103 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.