LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Most primitive way to print a file (file --> printer). (https://www.linuxquestions.org/questions/linux-newbie-8/most-primitive-way-to-print-a-file-file-printer-886104/)

stf92 06-13-2011 02:39 PM

Most primitive way to print a file (file --> printer).
 
Hi:

What is the mos primitive way to output a file to the printer? I mean data transfer from the file to the printer. I suppose it must be 'cp some_file /dev/<printer device>. For the console, I know the devices are /dev/ttyN, N= 1,2,... But I do not know what are the devices for the printer. Thanks



Thanks.

pljvaldez 06-13-2011 03:20 PM

Printer devices are usually /dev/lp0, I believe. A quick google yielded this and this.

jefro 06-13-2011 03:22 PM

More or cat should work also.

lpt is a basic mode. /dev/lp0


http://discussions.virtualdr.com/showthread.php?t=71241

stf92 06-13-2011 03:32 PM

Thanks for the links. It'll take some time to study them.

I'll do 'cp file1 /dev/lp0'. But what if I want to send some control chars. Or a shell script would suffice? That is: suppose I send them in the form 'cp <some control chars> /dev/lp0'. What would be the syntax for <some control chars>?

teckk 06-13-2011 04:41 PM

Code:

printf "This is a test\r\n\f" | lpr
http://linux.die.net/man/3/printf

Direct a postscript file to a postscript language printer.
Example
Code:

cat myfile.ps > /dev/lpt0
netcat can be used to print directly to network printers
Example
Code:

nc nethplaser 9100 < myfile.ps

stf92 06-13-2011 06:11 PM

Thanks for your post, teckk. From the manual, lpr seems to be far from being a primitive command. By primitive I mean the number of layers of software between the command and the hardware.

Also, printf, is a sofisticated command. There must be some way to send control chars with cp or cat. Perhaps

cat \0x0a /dev/lpt0 ?

pljvaldez 06-13-2011 06:34 PM

Maybe using a pipe with the echo command?

stf92 06-13-2011 06:44 PM

So a shell variable can contain non-printable chars? And cannot these chars be embedded in an ascii text file?

teckk 06-13-2011 07:37 PM

Quote:

What is the mos primitive way to output a file to the printer?
Send it to the device node that the printer is hooked to
Example
Code:

cat file.ps > /dev/ulpt0
You will have to have permissions to access that usb printer device node.
Quote:

But what if I want to send some control chars.
Then you'll need something that will do that like printf,
Code:

printf "This is a test\r\n\f" | cat > /dev/ulpt0
CUPS, LPR, a PCl filter, etc.
Or you could echo the character you want to the device node. You can write a shell script to automate that perhaps.

Why don't you post what you are trying to achieve and someone might be able to direct you.

If you are trying to access a printer, make carriage returns, line feeds, so that the document prints correctly,

That's what a print driver, a PCL filter that calls upon ghostscript, or sending the document in the same printer language that the printer understands does.

If you cat a .txt file to a PCL printer without a filter the txt will be all mixed up. Sounds like you already know that and are trying to make a print filter or printer driver for a particular printer language?

Just simply making a text file with control characters in the text won't give you what you want I don't think.

stf92 06-13-2011 10:57 PM

Thanks for your kind reply, teckk. If my file is 3 chars long, consisting of the string 'abc', then cat > /dev/lp0 will result in the string 'abc' being efectively printed on the paper. I never did it, but that's what in this thread has been said, and what common sense dictates.

What am I trying to do?: I have an old dot printer, connected to a paralell port in the machine. Some chars are typed in bold and some not (single and double strike of the needles).

When turning on power, the printer should initialize, although always some settings are done by the user by means of dip switches on the printer rear panel. The computer program writting to the printer has always priority over the these hardware switches.

I have the printer manual, including the colection of control chars it recognizes. And intend to send some of them, in an atempt to correctly inizilize it, an operation with low probabilities of success (I blowed a fuse up and had to open it; BEFORE THIs it worked pretty nice).

I hope I did not went very much away from the subject title. Regards.


All times are GMT -5. The time now is 03:00 PM.