Yanover Posted May 25, 2021 Share Posted May 25, 2021 I am a bit desperate about this problem that I have been trying to solve for several days now. I'm trying to run a Python script from the exec() function in php. The script is called but the print job is never executed. This process has been running for several years and for no clear reason it suddenly stopped working. On my home computer, it works without any problem. In my virtual machine, nothing happens. The print() functions present in the script are well displayed by the return value received by php but the printing is not executed. The virtual machine is a test environment, in production it is also an physical machine. PHP <?php exec("py C:\xampp\htdocs\test\test.py", $out, $res); echo "<pre>"; print_r($out); echo "</pre>"; echo "<pre>"; print_r($res); echo "</pre>"; ?> PYTHON if __name__ == "__main__": try: filename = "C:/xampp/htdocs/test/test.pdf" win32api.ShellExecute(0, "print", filename, None, ".", 0) except Exception as e: print(f "An error occured during print_pdf : {e}") The two environments are approximately the same: * Build 1909 * Python 3.9.5 * Apache 2 & php > 7 * local user member of the administrators group * local user owner of the apache2 service * Same printer configured by default I'd like to point out that running the script directly from the CLI works on both machines. On the problematic machine, exec() only returns the result of print(..) I already opened a thread a few months ago about this problem but received no response. Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/312789-php-shell-function-not-executing-python-script/ Share on other sites More sharing options...
gw1500se Posted May 25, 2021 Share Posted May 25, 2021 Do you have errors turned on in PHP? error_reporting(E_ALL); What error do you get? You need to check what 'exec' is returning? Out of curiosity, why are you using Python rather than executing the API directly? Quote Link to comment https://forums.phpfreaks.com/topic/312789-php-shell-function-not-executing-python-script/#findComment-1586801 Share on other sites More sharing options...
Yanover Posted May 25, 2021 Author Share Posted May 25, 2021 Hey gw1500se, thank you for your answer ! Yes, I've try to display all php error. Unfortunately, nothing is written in error.log (c:\xampp\apachelogs\error.log) To give a little more information, the problem has nothing to do with the printing process, even when trying to simply open the file, nothing happens through the browser! And if I go through the CLI, it works! Once again, the service operator is in the administrators group of the machine and no error either on the php or python side is detected. Quote Out of curiosity, why are you using Python rather than executing the API directly? The code snippet above simply highlights the problem. The real problem occurs on an application I developed during my studies which is now in production. The Python script concerned by the problem performs some manipulation on a .pdf file passed to it. It is true that today I would certainly not proceed in this way! Thank you again for you time Quote Link to comment https://forums.phpfreaks.com/topic/312789-php-shell-function-not-executing-python-script/#findComment-1586804 Share on other sites More sharing options...
requinix Posted May 25, 2021 Share Posted May 25, 2021 6 hours ago, Yanover said: This process has been running for several years and for no clear reason it suddenly stopped working. Stuff does not simply "suddenly stop working". Find out what's changed recently: maybe someone reconfigured PHP, maybe they upgraded versions, maybe they altered how Apache runs, whatever. Quote Link to comment https://forums.phpfreaks.com/topic/312789-php-shell-function-not-executing-python-script/#findComment-1586805 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.