开发者

PHP exec() command wont launch python script using sendkeys

开发者 https://www.devze.com 2023-04-03 20:43 出处:网络
First Note: Sorry this is long. Wanted to be thorough. I really hate to ask a question when there\'s so much out there online but its been a week of searching and I have nothing to show for it. I\'d r

First Note: Sorry this is long. Wanted to be thorough. I really hate to ask a question when there's so much out there online but its been a week of searching and I have nothing to show for it. I'd really appreciate some help. I am a noob but I learn very fast and am more than willing to try alternate languages or whatever else it might take.

The goal: What I'm trying to do is build a Netflix remote (personal use only) that controls Netflix on the server (Windows 7 PC 32-bit) via keyboard shortcuts (example: spacebar to pause) after a button is pressed in a php page on my ipod touch or android phone. Currently the remote uses USBUIRT to control the TV and IR devices without issue. If you have any alternate methods (that I can build, not buy) to suggest or other languages I could learn that can achieve this, I'm happy to learn.

The issue: PHP's exec() and system() commands will not launch the python script (nor an exe compiled with py2exe) that simply presses the Windows key (intended to press the key on the server, not the machine loading the php page). I can use USBUIRT's UUTX.exe passing arguments with exec() to control IR devices without issue. But my exe, py, nor pyw files work. I've even tried calling a batch file that then launches the python script and that batch will not launch. The page refreshes and no errors are displayed.

Attempted: Here's a code that works

$exec = exec("c:\\USBUIRT\\UUTX.exe -r3 -fC:\\USBUIRT\\Pronto.txt LED_Off", $results);

Here's a few attempts that don't work

$exec = exec("c:\\USBUIRT\\test.py", $results);

$exec = exec("python c:\\USBUIRT\\test.py", $results);

$exec = exec("C:\\python25\\python.exe c:\\USBUIRT\\test.py", $results);

All of those I've tried without the dual backslashes and with forward slashes and dual forward slashes. I've left off passing it to variable $exec and that makes no difference. $result outputs Arraystring(9) "

Copying everything in the exec() into command line works correctly. I've tried moving the file to the htdocs folder, changed folder permissions, and made sure I'm not in safemode in php. Var_dump returns: Array" Using a foreach loop gives no info from the array. My logs for Apache show only

[Sat Sep 10 19:54:09 2011] [error] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/announce

Setup: Apache 2.2, python 2.5, and php 5.3. Running this on Windows 7 and only connect on the local network, no vpn or the like. Given every associated folder (python, htdocs, the cmd.exe file, usbuirt folder) IUSR, admins, users, and everyone with full control just for initial testing (later I'll of course tighten 开发者_如何学Csecurity up). Safe mode is off on php as well.

Notes: This code I saw on another similar issue doesn't work:

exec("ping google.com -n 1");

No errors in error.log nor event viewer. Putting it inside ob_start(); and getting the results with ob_get_clean(); gives me absolutely nothing. No text or anything at all. I've tried a lot more but I've already written a novel on here so I'll just have to answer the rest as we go. I'll post the full php source or the python script if that is needed but all it does is import sendkeys and press the windows key to pop open the start menu as a basic visual test. I don't know if its permissions, the way I have my setup running, my coding... I just don't know anymore. And again I apologize this is so long and if you do answer, I really appreciate you taking the time to read all this to help out a total stranger.


The PHP server running the script is most likely running as a different user (Network Service) than the account logged in at the GUI Console. I think this kind of setup might work under XP, and/or with the "interactive" field enabled on the service. However, I believe in Vista/7 it is blocked on security grounds. Details are a bit fuzzy as I'm now in front of a Linux box.

A solution would be to run php manually in the session that is running netflix and try again. If this doesn't work, I once wrote a simple client/server in python that takes key commands and converts them to keystrokes. Was pretty easy to do.


Figured it out thanks to the excellent help from Winston Ewert and Gringo Suave.

I set Apache's service to the Local System Account and gave it access to interact with the desktop. This should help if you have Windows XP or Server 2003, but Vista and newer there's an Interactive Services Detection that pops up when you try to launch GUI applications from php. Every command was executing correctly, but were doing so in Session 0. This is because Apache was installed as a service. For most people I would think that reinstalling without setting up Apache as a service would work, but I was considering moving to XAMPP anyway, so having to uninstall Apache helped push my decision.

Ultimately all of the codes I wrote in my original post now work as a result, and my project can move forward. I hope someone else stumbles across this and gets as much help from Winston Ewert and Gringo Suave as I did! Thank you both very much!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号