Using PHP shell_exec to print PDF on the network automatically to a network printer not working

I'm using shell_exec() to print a PDF that is stored on a LAN automatically to a printer on the LAN through Adobe Reader using the following PHP code (all on one line):

shell_exec("'C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe' 
/t \\hnurensp01\RepairTickets\179694.pdf \\hnurenfp01\Accounts_FS-1128MFP");

What I expect this to do is open adobe reader, open the PDF on the network and print to the network printer. When running the PHP script with this line, it doesn't open adobe reader or print it. However, when I copy that code and execute in a command prompt (client-side), it works and prints. There is only slight modifications to the command line (all on one line):

"C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe"
/t \\hnurensp01\RepairTickets\179694.pdf \\hnurenfp01\Accounts_FS-1128MFP

Is it to do with the PHP script executing on the server-side? I've tried running the same command line on the server and it works too. It just seems to be when it's going through PHP, it does nothing.

My end result must be printing out a server-side PDF with as little interaction from the end-user as possible. Note: this is a WAMP environment.

Any ideas?


UPDATE: Tried put the code into a batch file and calling it that way, still didn't work. Tried using exec() and shell_exec() but still no joy. For some reason when I run the batch file by double-clicking it, it works fine. It's when I call it using PHP, it doesn't do anything except open two instances of acrord32.exe that doesn't close and therefore the PHP script seems to never complete. I'm soo confused...


Try this:

echo "'C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe' /t \\hnurensp01\RepairTickets\179694.pdf \\hnurenfp01\Accounts_FS-1128MFP"

It returns:

'C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe' /t \hnurensp01\RepairTickets9694.pdf \hnurenfp01\Accounts_FS-1128MFP

In PHP, the backslash serves as a 'special' character, since it's used to produce tabs and newlines \t and \n. The proper way to escape a backslash, is by prepending another one: \\ produces \ as output.

This is why your PHP script doesn't work. The double backslashes will be printed to the shell as if you only typed one! You will need to escape every backslash in that line of code:

shell_exec("'C:\\Program Files\\Adobe\\Reader 10.0\\Reader\\AcroRd32.exe' 
    /t \\\\hnurensp01\\RepairTickets\\179694.pdf \\\\hnurenfp01\\Accounts_FS-1128MFP");

Need Your Help

Javascript template engine which would come with a precompilation script?

javascript template-engine mustache precompiled ejs

I am searching for the javascript template engine which ships with the precompilation script + watcher. How would I see it:

How can I make a java.lang.reflect.Proxy from two separate classloaders?

java osgi classloader

I use the CXF JAXRSClientFactory to create proxy instances out of various JAX-RS interfaces. Deep inside, this factory invokes Proxy.newProxyInstance(), passing in my interface and the CXF Client

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.