Help !! I need to send a .prn file to thermal printer

Dear all,

After creating a .prn file to send to thermal printer I did some test directly from DOS cmd and it worked.
copy “C:\Temp\ est_sato.prn” “\Asus-PC\SATO CT408i”

Now I’m trying without success to do the same command from SC button script :

$output = shell_exec(“cmd copy ‘C:\Temp\ est_sato.prn’ ‘\Asus-PC\SATO CT408i’”);
echo “<pre>$output</pre>”;

There is no way that it works. I’m under Windows7 Wamp environment.

If I leave ‘cmd’ then the SC try to run the code but it goes stucked and I have to exit, clear all cookies and re-run all SC . The same with cmd.exe …
If I do not use ‘cmd’ and only copy ‘C:\Temp\ est_sato.prn’ '\Asus-PC\SATO CT408i then it gives me a error like Sintax of command wrong

I checked also php.ini and parameter is safe_mode = Off

Please I stucked here …

it may be that you do not have the rights to perform shell_exec, apart from that cmd has to be called cmd.exe (and probably with the complete path).
I guess that $output = shell_exec(“c:\windows\system32\cmd.exe /C copy ‘C:\Temp\ est_sato.prn’ ‘\Asus-PC\SATO CT408i’”); has more chance to work.

Hi rr,

thanks !
I’m under W7 and I’m using the development environment of SC as usual. Then I will deploy application under WAMP environement .
How can I grant the permission in both situations ? Is W7 needing these rights too ?
May use , just for testing your command, also exec(… ? or is it not correct ??

Well you are running your server under windows 7, so basially your apache service runs under windows 7 with a limited set of rights. Go to your services, find your apache service and check the properties. Somewhere in there you see that you can run the service as another user. The default use (so none is selected) is limited in what it is allowed to do. That user is not allowed to run various things for example (for details better use google). As a first attempt just fill in your own user with password and simply restart the service.
I also suggest you try a small php script BY HAND that does that copy command to test whether the script is correct. If you are running under 64 bit windows then you can still use the 32 bit cmd.exe but you should also be able to use the 64 bit version. By the way another way to do this is not by using copy but by simply copying the contents of C:\Temp\ est_sato.prn to CT408i device.
I forgot to say that you should actually use copy /b instead of copy…
You may also need to set up a device properly (see for example http://h30434.www3.hp.com/t5/Printer-Networking-and-Wireless/how-can-I-sent-a-prn-file-to-my-networked-printer-in-windows/td-p/2530903 ).

I havent tested the php printing tho but I know that copy /b to a device normally works. So a read from file/write to device piece of code should normally also work.

Great !!
The command did from C:> worked --> copy “C:\Temp\ est_sato.prn” “\Asus-PC\SATO CT408i”
I will check apache service as you suggested and then l’ll let you know.
When you say by simply copying the contents of C:\Temp\ est_sato.prn to CT408i device. is it different from the above copy ?

I just tried once again under the prompt DOS using also another home printer.

The only sintax that works is the following

copy /B C:\Temp est_sato.prn “\Asus-PC\EPSON Stylus DX9400F Series”

I’ve tried to create a short php program under WAMP (out of SC)

  1. exec(copy /B C:\Temp est_sato.prn “\Asus-PC\EPSON Stylus DX9400F Series”);
    It gave a sintax error on “C”…

  2. Added a variable instead of C…
    <?php
    $aaa=“C:\Temp\ est_sato.prn”;
    exec(copy /B $aaa “\Asus-PC\EPSON Stylus DX9400F Series”);
    ?>
    It does nothing and no error

  3. Added also the cmd.exe
    <?php
    $aaa=“C:\Temp\ est_sato.prn”;
    exec(c:\windows\system32\cmd.exe copy /B $aaa “\Asus-PC\EPSON Stylus DX9400F Series”);
    ?>
    Still nothing at all

That’s incredible !

you cant exec(“copy …”) because copy is a command of cmd.exe. Just type cmd.exe /? . There is no copy.exe
You CAN use xcopy.exe tho if you have that installed. I guess it does a binary copy (like copy /b). But you still have to have the rights to perform that command.
Copying to a device can be done using exec(“c:\windows\system32\cmd.exe /c copy yourfilename PRN1”) if your PRN1 device is set to your printer.
Anyway check out http://filext.com/faq/print_from_prn_file.php that should make it clearer.

A workaround could be use a .bat file with dos command lines.
In some way it runs and the files is copied into printer device.

HI rr,

I did the job ant it works nice, but , unfortunately, the customer do not avoid at all to use a “Shared” printer .
So now I’m here stucked again… :wink:
I did so many tests changing the approach but now when I run the code (see example below) the file goes into printer spool and remain stucked there with no output. I’m using USB port .
I’m really sad becouse it’s the last part of the project but I can’t deliver nothing for that reason.
Attached spooler files and .prn sample I’m using.

<?php

$file_to_print = “C:\inetpub\wwwroot\Test\ est_sato.prn”;
$content_file_to_print = file_get_contents($file_to_print);
$handle = printer_open(“SATO CT408i”);
printer_set_option($handle, PRINTER_MODE , “RAW”);
printer_write($handle, $content_file_to_print);
printer_close($handle);

?>

files.zip (86.5 KB)

Did you checked this?
http://www.scriptcase.net/forum/showthread.php?6322-How-to-print-a-receipt-using-POS-printers&p=23752&viewfull=1#post23752