Jump to content

Recommended Posts

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.
 

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 :)

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.