I tried to execute a .jar using HTML or PHP.
In the first case I wrote the code below:
<applet code=Diagnostica.class
archive="Diagnostica/Diagnostica.jar"
width="120" height="120">
</applet>
This way doesn't work cause the file Diagnostica.jar need to contain an applet I suppose.
So I tried the second option in PHP:
exec("java -jar Diagnostica/Diagnostica.jar");
This way it works. Diagnostica.jar starts outside the browser, but I want to start it inside the browser.
How can I do?
If that file does not contain an Applet, I do not think you will be able to start it in the browser (have a look here).
Executing it via exec should work like executing it via the command line - but as you already noticed, it will be run on the server - not the client.
If it should run on the client, you'll either have to use a Java Applet or let the user download the jar-executable and execute it via command line etc.
Related
I want to open a vm through following php code:
<?php
$output = shell_exec("virt-viewer --connect qemu:///system 1 2>&1");
echo "<pre>$output</pre>";
?>
I already set the permission of a file with read,write and execute.
I am getting the following error:
(virt-viewer:15162): Gtk-WARNING **: 22:45:33.686: cannot open display:
please help if i am missing something or doing something wrong.
Thanks
How web page works:
Browser makes request to web server, web server delivers html and optionally other asset files (css, js..), but generally, html is loaded first and it stays as it is - content is not changed (except if it's changed by JS, which is not the case here).
Your call will execute some shell command it will return some response (some text) and you'll get it inside some var. If you display that static text as part of your page how do you expect that it will act as GUI?!?
That's just not possible. Imaging that you are calling from shell_exec() exe file of some video game? Will the game then run in the browser?!?
You can call shell commands in order to trigger some action on server (i.e. rescale some image, process some video) or to collect some response (i.e. free disk space or something). But expecting that if you call something form shell will appear in browser is just not realistic.
I have SWI Prolog working in my vm where I'm going to be working on a PHP/HTML website. I've been following this guide: http://www.j-paine.org/dobbs/prolog_from_php.html#appendix to set up my php file to receive the output from the executed prolog file. The problem that I'm having is that it seems that the output from SWI's command line (which I'm executing from my bash terminal) isn't being captured as a standard output that I can get PHP to recognize. So, in my terminal, when I execute SWI and a test prolog file, it writes out like I need it to, but I can't figure out how to capture that output to then use in PHP.
Any ideas or suggestions would be really great. Thanks!
I having a simple problem, I guess.
I am working on an iPhone app which I can send ASIHTTPRequest to my php server (with go daddy). The php script then gets the command and run like:
$this->pdo->beginTransaction();
//do some other simple works
exec ('/usr/local/bin/php -f /path/to/my/script/test.php') ;
$this->pdo->commit();
which is suppose to run another php file within my own server (dedicated)!!! But it does NOT do anything. It does work with curl_exec() though, but I want to use another method which I can put it to work in the background server.
My planning was that I want to send too many APNS (notification) but instead of waiting for the whole list to be done, it is better to get back and let the work done in the background!! How can I do that.
When I got connected using SSH command line. I can easily call "test.php" and it works so fine. But I can not do the same thing from the above php code.
Any help is appreciated.
Use PHP Include? That will run the script.
Put something like this inside an IF Statement.
include 'YourPage.php';
My first thought is that GoDaddy might not allow exec() to be run for security purposes.
I am trying to run an octave script through PHP. I already googled and found some results but none of them are working for me. I tried with exec() and system(). I even created a batch file which calls 'octave myScript.m" and called this bat file using system() of PHP but it doesnt seem to work. In the browser page I am just seeing 'C:/FOLDER_PATH>octave myScript.m". The octave script simply creates a new file and writes some text to it. When i directly run the bat file (by double-clicking on it), the file is getting created properly. I also added folder path to octaverc file but it doesnt seem to work. I need to do some image processing in octave for which I already wrote the script. I need to invoke this script on a client request and send the result to back the client. I am checking the invocation process through a sample script which as I mentioned earlier creates a new file. What am I doing wrong?
My php code is this:
$cmd = "cmd /c C:\PATH_TO_BAT_FILE\myBat.bat";
exec($cmd,$output);
system($cmd);
echo implode ("\n",$output);
Note that my path contains double backslashes to avoid escape sequence characters
My bat file is this
octave temp.m
My octave code(temp.m) is this
fid = fopen("helloScript.txt",'w');
fprintf(fid,"Hello world!");
fclose(fid);
Ouput on the webpage is this:
C:\PATH_TO_BAT_FILE>octave temp.m C:\PATH_TO_BAT_FILE>octave temp.m
I can see in the task manager that a new process is getting created whenever I run the PHP script in browser (I am guessing that it is cmd).
Also, when i change my bat file to
echo hello
I am able to see the following in my browser page
C:\PATH_TO_BAT_FILE>echo hello hello C:\PATH_TO_BAT_FILE>echo hello hello
So this could mean that the bat file is getting executed properly. But when I replace the bat file script with 'octave MY_FILE.m' I am not able to see the output. It may mean that my octave is not configured properly? or is there something I am missing?
Any help would be appreciated.
Thanks
If you are going to run the batch file to create it in php then the php command should be like this.
exec('cmd.exe /c C:\path\to\test.bat');
This is embarassing but I solved it by giving full path. In the bat file I specified the complete path of the octave.exe (C:\Software\PATH_TO_OCTAVE.EXE) and the complete path of the '.m' file.
In my php, I just used exec()
I am trying to run a shell script from a php script.
I have complete control of the environment (unix on mac), I should have all the permissions, etc. set correctly.
The web script is in /htdocs/
The shell script can be executed from anywhere so when I go to /htdocs/ in the shell, I can easily run it like this:
$ my_shellscript
.. but when my php script (which is located in htdocs) tries to call it:
shell_exec('my_shellscript');
I get nothing.
I have proven the script can be called from that location and I have temporarily granted full access to try to get it working somehow. I am going crazy, please help.
If you know of some other way of triggering a shell script via the web that would be fine.
Thanks in advance.
well i got few weeks same problem, the solution is to check if the apace has the permission to execute your script. You could also try to run the script in php cli.
Since it is a shellscript, it needs to be invoked with the path prefix. My guess is you need to do this:
shell_exec('./my_shellscript');
First thing: make sure php isn't running in Safe Mode
Next thing: Try running it with the exec() function and using the full path (e.g. /var/www/htdocs/my_shellscript)
Try doing
echo shell_exec('my_shellscript 2>&1');
which will capture the script's stderr output and print it out. If something inside the script is failing, this output would otherwise be lost when not being run interactively.