LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-11-2009, 10:49 AM   #1
friendlynotnice
LQ Newbie
 
Registered: Nov 2009
Posts: 2

Rep: Reputation: 0
Write a file, then wait for someone to print it


Hi,

the application I am using writes a report file (ascii), but I am not able to print it, because from inside the application I have no access to the shell and so cannot invoke any printing command (lpr, lp, ...). Is there a tool/daemon which waits for a file in a given directory, takes it, and sends it to a printer?

Thanks,
Patrick
 
Old 11-11-2009, 11:31 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,808

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Welcome to LQ!!

I was under the impression that most languages had some kind of "system call" for such things. What language are you using?

regardless, it should be fairly simple to write a small script that continuously scans a folder for a particular filename, and then prints it. e.g., put something like this into an endless loop (use a loop delay of at least 30 seconds to keep your machine from "churning"):
Code:
find . -name words|xargs lp
Rigorously, I imagine that the script would be run in the background.
 
Old 11-11-2009, 11:44 AM   #3
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 97
A couple of things.

First, I would check that the file has finished writing, generally by checking if the file is more than 2 minutes old:
Code:
find . -mmin +2 -name words|xargs lp
Second, I would suggest that after it has printed the file, you may want to move/remove it.
 
Old 11-11-2009, 12:34 PM   #4
pcunix
Member
 
Registered: Dec 2004
Location: MA
Distribution: Various
Posts: 149

Rep: Reputation: 23
To check that it is finished writing, I'd use lsof or fuser.

But:

If your app can write to a named pipe or a network socket, it's easy to setup a listener for the socket or a daemon reader for the named pipe - either one will allow instant response rather than watching for the file.

If you need script examples, I can provide for either or both.
 
Old 11-11-2009, 01:19 PM   #5
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 97
I've had inconsistent results from fuser, which is why I tend to check modified time.

Haven't used lsof though it looks interesting.
 
Old 11-12-2009, 02:54 AM   #6
friendlynotnice
LQ Newbie
 
Registered: Nov 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Regarding the language: I think it is a MVS-application migrated to *nix, the configuration files are called "JCL" :-)

I just retrieved a thought from the long, dark corridors of my minds' long term storage: isn't there a possibility to create an entry in /dev which really is a shell script that calls my printing commands? I have the feeling that I once read about this ...
 
Old 11-12-2009, 05:26 AM   #7
pcunix
Member
 
Registered: Dec 2004
Location: MA
Distribution: Various
Posts: 149

Rep: Reputation: 23
Quote:
Originally Posted by friendlynotnice View Post
Regarding the language: I think it is a MVS-application migrated to *nix, the configuration files are called "JCL" :-)

I just retrieved a thought from the long, dark corridors of my minds' long term storage: isn't there a possibility to create an entry in /dev which really is a shell script that calls my printing commands? I have the feeling that I once read about this ...
That's what I mentioned above: a named pipe (doesn't have to be in /dev) with a daemon listening to it.

Like this:
Code:
mknod /dev/myfakenetprint p

That creates a "device" that your application can print to. Use "chmod" as necessary to give it whatever permissions you need (666 if everyone needs to use it).

Now you need something that runs all the time in background. It's a shell script and it needs to start automatically whenever the machine is rebooted:

Code:
while :
do
exec </dev/myfakenetprint 
lp -dmyrealnetprinter
done

(On a very busy system, it's possible for your app to send new data to the pipe before your reader process has sent it to the print server. You could implement a cooperative locking system to prevent that, but a small sleep at the end of the interface script might also work. Most often this is not an issue.)

More details at http://aplawrence.com/SCOFAQ/FAQ_scotec7netdevice.html
 
  


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
write a programme to print function name bhupendra1984 Linux - Newbie 2 09-10-2009 11:37 PM
How to print wait reason in linux senrooy Linux - Kernel 4 02-03-2009 11:21 PM
Print-to-file print driver to print PDF Bill Fox Linux - General 3 05-02-2006 04:15 PM
Write shell commands to print ricki Programming 2 07-31-2005 03:52 PM
Setting up a print to file print driver Bill Fox Linux - General 0 02-26-2005 01:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:44 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
Open Source Consulting | Domain Registration