LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-13-2011, 03:39 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,625

Rep: Reputation: 51
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.
 
Old 06-13-2011, 04:20 PM   #2
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 271Reputation: 271Reputation: 271
Printer devices are usually /dev/lp0, I believe. A quick google yielded this and this.
 
Old 06-13-2011, 04:22 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 17,101

Rep: Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552
More or cat should work also.

lpt is a basic mode. /dev/lp0


http://discussions.virtualdr.com/showthread.php?t=71241
 
Old 06-13-2011, 04:32 PM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,625

Original Poster
Rep: Reputation: 51
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>?
 
Old 06-13-2011, 05:41 PM   #5
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 1,877

Rep: Reputation: 253Reputation: 253Reputation: 253
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
 
1 members found this post helpful.
Old 06-13-2011, 07:11 PM   #6
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,625

Original Poster
Rep: Reputation: 51
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 ?
 
Old 06-13-2011, 07:34 PM   #7
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 271Reputation: 271Reputation: 271
Maybe using a pipe with the echo command?
 
Old 06-13-2011, 07:44 PM   #8
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,625

Original Poster
Rep: Reputation: 51
So a shell variable can contain non-printable chars? And cannot these chars be embedded in an ascii text file?
 
Old 06-13-2011, 08:37 PM   #9
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 1,877

Rep: Reputation: 253Reputation: 253Reputation: 253
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.
 
1 members found this post helpful.
Old 06-13-2011, 11:57 PM   #10
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,625

Original Poster
Rep: Reputation: 51
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Print to File Printer cov Linux - Hardware 1 01-12-2010 05:13 AM
How print file from my OLPC X/O to my Brother printer? roserose Linux - Newbie 1 05-07-2009 06:39 PM
Printer Dell 3115, I can't print several specimen of file briiice Linux - Hardware 1 11-08-2007 05:01 AM
Printer Configuration: "Print file sent, waiting for printer to finish", JetDirect Ed-MtnBiker Fedora 3 02-23-2007 01:41 PM
Cups: Print file sent, waiting for printer to finish.. Gurr Linux - Newbie 2 07-24-2006 07:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration