PHP Command line not working the same


#1

Hey So i am trying to run a command in windows from php. i have a php file that runs a program PDFtoPrinter

so the php looks like

$output = shell_exec(‘C:\PDFtoPrinter\PDFtoPRINTER.exe C:\Wamp\www\upload\’.$file;
echo $output

so if i run
C:\PDFtoPrinter\PDFtoPRINTER.exe C:\Wamp\www\upload\file.pdf
in command prompt it works great and prints two sided

when it runs through the php file it prints two pages one sided each.


#2

Well, you are talking about two different systems. They are NOT the same system.
If you have a standard install for Wamp, you have an Apache based server running for an example.
But, both will use your current default Windows printer setup. This is what PDFtoPRINTER.exe’s site says:

Duplex printing: PDF-XChange Viewer cannot save a duplex-printing option as the default. To print in duplex mode, modify the settings of your Windows printer (in the Windows Control Panel or Settings app) to enable duplex printing, or create a duplicate copy of your Windows printer, set it to print in duplex by default, and specify that printer when running PDFtoPrinter.exe. Search the web if you don’t know how to create a duplicate copy of your Windows printer or if you don’t know how to specify duplex printing in your Windows printer properties.

So, are you testing as a website or or just using Wamp to let you run PHP code locally? Wamp is a complete emulator of a website server with PHP installed on it. If you are using the PHP to just print items, you can have the line printer option send the PDF file to the printer. The defaul setting inside the printer must be set to duplex mode. Something loosely like this should work:
shell_exec(’/usr/bin/lp -P “C:\Wamp\www\upload” . $file);
It doesn’t use the outside executable program, but just sends the file to the printer. Might work…

On further research for you, if you use the shell-exec to call an .exe file, you need to escape each backslash you have in the command. So, try this and see if it works:
$output = shell_exec(‘C:\PDFtoPrinter\PDFtoPRINTER.exe C:\Wamp\www\upload\’.$file;
This might work, too…


#3

Apologies for jumping into this…

This looks to me like path from linux based system, so it is puzzling me quite.Does this have to do with printer’s own OS?


#4

both for your responces. As cluster said wouldnt /usr/bin/lp -P just be for linux systems?

So i am using wamp and i have a php file. From a tablet i am sending over information that is getting saved into the wamp data base and then creates a pdf from some images that were sent over and then it is set to print. Could it have something to do with windows having the printer defaults right for the windows user i am manually typing the command line. when the php is run from an outside source would that be under a different user / different printer defaults?


#5

Well, it depends on how the system was set up. That is why I put in the Windows command near the bottom of my post.
$output = shell_exec(‘C:\PDFtoPrinter\PDFtoPRINTER.exe C:\Wamp\www\upload\’.$file;
Try that and see if it works.


#6

if i start taking out the backslashes so there is only one at each folder there is an issue with the ’ ’ not working for what is inside them.


#7

Ok so i got it figured out. Running on the theory it apache was using a different user i went through this link
https://blog.lysender.com/2009/07/run-apache-as-local-user-windows-xp/


#8

Yes, you need to escape slashes for all folder and sub-folders.

But, What version of Windows are you using?
Do you have Adobe Acrobat Reader installed on it?

If so, just use the AR system to print it. To do that without the outside program, it is done like this:
shell_exec(“C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe” /t “$file”);
The AR address depends on your Windows set up. You might have to change it if you are not using ver 10…


#9

You replied and i was looking up the AR command version.

Interesting that your user account control was locking out sending to the printer.
Never thought of that at all. I will have to try to remember that issue. Thanks for letting us know about it!


#10

it wasn’t necessarily locking out sending to the printer. It still sent to the printer but was not using my printer setting i used to say for it to duplex.
I really appreciate your help


#11

Still very interesting to me! It was most likely not using the local “default” printer setup and using a default on the Wamp server or linux whatever instead. Thanks again for this and glad you solved it!