I have a shell script that requires user input. This script executes xwininfo, which is a utility for the X server that waits for the user to click on a window so that it can return info about it.
When I use PHP's exec, shell_exec, or system functions, they all execute the script as if xwininfo was never called. My guess is that when PHP executes a shell script, it can't transfer the focus to the script, and thus it never waits for user input and goes on like it doesn't exist.
My question is whether I can execute a shell script from a web page that gains the focus, receives user input, and outputs its info, while PHP waits for the script to finish before serving the page back to the browser? This just doesn't seem possible from my testing so far.
I haven't tried it yet, but the only difference between the passthru function and the exec function is just output. You get raw binary data with the passthru. I'm not looking for that. I'm looking for the PHP server to wait on serving the page while the shell script takes focus and does what it needs to do first.
I haven't tried it yet, but the only difference between the passthru function and the exec function is just output. You get raw binary data with the passthru. I'm not looking for that. I'm looking for the PHP server to wait on serving the page while the shell script takes focus and does what it needs to do first.
-Shane
Quote:
This function should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser
that's all what you get, this is not Star Wars, and php is not the Force,
when you run xwininfo all mouse events will be directed to the x server untill somebody will click somewhere on that server( the one who run x not the one with the browser if there are different) and then, probably, the output of xwininfo will apear in browser.
I didn't try and I'm not sure about this scenario but this is how I think will work,
I haven't tried it yet, but the only difference between the passthru function and the exec function is just output. You get raw binary data with the passthru. I'm not looking for that. I'm looking for the PHP server to wait on serving the page while the shell script takes focus and does what it needs to do first.
-Shane
back after a short test. I was wrong about how it work. It don't do nothing.
script:
will output 1 and in xwininfo man page I didn't find when xwininfo return a status like that.
sorry for negative answer but look to the bright side of that story, you don't waste time with this and you can focus to search another way to achive what you want,
that's all what you get, this is not Star Wars, and php is not the Force,
Unnecessary comment. I'm well aware of most of the capabilities and limitations of PHP and other server-side languages. I'm not looking for PHP to do any magic; just execute a shell script that requires a mouse event in order to finish processing.
Quote:
Originally Posted by oesxyl
when you run xwininfo all mouse events will be directed to the x server untill somebody will click somewhere on that server( the one who run x not the one with the browser if there are different) and then, probably, the output of xwininfo will apear in browser.
I didn't try and I'm not sure about this scenario but this is how I think will work,
You're not understanding my dilemma. The problem is not receiving output from the script. I already have web pages that run shell scripts and output back to the browser. My problem is that when PHP executes xwininfo, it does not wait for a mouse event and/or cannot detect the mouse event. My belief is that there is an issue with a web page calling a shell script that requires user input or interactions, i.e. mouse events.
In my experience, when a shell script is executed from within PHP, the server will wait for the script to finish before the page is served up again. There are ways around having your server wait for a script to finish before serving it up (which I've also done before), but in this case, I would actually like that to happen. I want the server to wait for the script to finish executing. The script should not finish until you 'left click' a window.
In my test cases, however, when PHP executes the script, there is no opportunity to 'left click'. It's as if xwininfo never executes inside the script. I can't figure out whether this is because PHP has problems calling scripts that require user input/events, or if it has something to do with a user/permission problem of the apache user possibly. The apache server and PHP module all run on the same box that I'm attempting to use this script on. And yes, the script works when it's called from the command line.
So what I'm looking for is anyone with experience with having PHP call a shell script that requires user input and/or mouse events. It may or may not be possible, and so I'm hoping there is someone out there that has tried something similar before.
When you ran that test, were you given the typical + icon and a chance to select a window before it echoed back your result? Did the server wait for you to click? Theoretically, I would think that your browser would show that it's loading as your server waits for you to click a window so that it can finish executing the xwininfo command and serve up your page.
My guess is it didn't do that for you and that is exactly the dilemma I'm having.
When you ran that test, were you given the typical + icon and a chance to select a window before it echoed back your result? Did the server wait for you to click? Theoretically, I would think that your browser would show that it's loading as your server waits for you to click a window so that it can finish executing the xwininfo command and serve up your page.
My guess is it didn't do that for you and that is exactly the dilemma I'm having.
-Shane
it's no dilemma here, when you run a script in browser it run in a different envoirment.
try this:
run same script from comand line with php -f script-name and will wait until you click on something and output the result. with a 0 status, that mean ok.
the problem is that runing in the browser it can't find x server.
Anyway have no sense what you want because x server run on one server, let's say A, and the browser can run on another server, let's say B separated by net.
how do you expect to click with your mouse on B and process the event on A?
I don't know if is what you want but for remote x apps there is alread a mechanism. Let's me know if this is what you intend to do.
Exactly. That is the problem for me in which I'm trying to find a solution to. The xwininfo command failed and gave you that output. I can't have that.
Quote:
Originally Posted by oesxyl
run same script from comand line with php -f script-name and will wait until you click on something and output the result. with a 0 status, that mean ok.
I figured it probably would, but wasn't sure since I haven't tested that yet.
Quote:
Originally Posted by oesxyl
the problem is that runing in the browser it can't find x server.
Now this may be the case. I need to do some more testing. I need to find a way for a web browser to execute xwininfo.
Quote:
Originally Posted by oesxyl
Anyway have no sense what you want because x server run on one server, let's say A, and the browser can run on another server, let's say B separated by net.
how do you expect to click with your mouse on B and process the event on A?
I don't know if is what you want but for remote x apps there is alread a mechanism. Let's me know if this is what you intend to do.
This project is an internal project. It will not be on the internet. The web page will always be displayed on the same box as the apache server and X server. There will not be any remoting when utilizing this page and script.
I need to find a way for a web browser to execute xwininfo.
This project is an internal project. It will not be on the internet. The web page will always be displayed on the same box as the apache server and X server. There will not be any remoting when utilizing this page and script.