Printing to Windows network printer in Perl WITHOUT shell command - windows

I have a printer, an HP DeskJet 712C, shared via a Windows XP workstation. I am able to print to this printer from various applications, but I am unable to print to it (from the workstation the printer is attached to or any other) via the PRINT shell command. I have a Perl script, currently hosted on a Windows 7 workstation, that generates text files. I would like those text files printed to the aforementioned printer, but as I am unable to use the PRINT shell command, I don't know how. How can I print these text files to that printer in Perl?

I don't know much about windows programming, but there are a couple of options I can think of.
Printer - There is a module on CPAN called Printer that claims to handle windows printing. I haven't used it. YMMV, but it looks like exactly what you want.
Wx - The Wx GUI toolkit has nice, windows compatible printing capabilities. It, sadly, is also a huge, complex dependency to add just for a simple command line script. I have used this and it works very nicely.
Win32::API - Here's where my Windows ignorance really shows. The Win32::API module lets you call into windows DLLs. If you know the appropriate functions/DLLs to use, you could access them to get a print job started.
Update
You might want to check out this thread on ActiveState's Perl-Win32 users' list.
Apparently you can just do:
open my $prn, '>', '//mycomputer/PrinterShare' or die "Oh noes $!";
print $prn "Here's some text to print.";
This is untested, untried, and maybe untrue, but give it a shot. What could possibly go wrong? Printers are cheap these days. ;)

Related

Ghostscript PDF printing

I would like to make my own "PDF printer" using Ghostscript.
Most of solutions I find on the internet involve a 3rd party like Redmon to redirect the PS printer to the Gs executable.
Is there a way to do the same without a 3rd party (other than Gs) ?
Here is my 2 ideas:
Bypass the printing driver and generate Postscript directly by software (From GDI to postscript, using maybe a custom device context like the Metafile device context exist)
Create programmatically a new local port for each document to convert. Maybe using this technique : https://stackoverflow.com/a/1331777/99276
The first solution would be great, but can't find anything about it.
And I am efraid the second is not efficient at all (and detect when the document is fully printed can be tricky)
Update: I used print apis to print in a temp file (the print is synchronous) and then convert the PS file with Gs
Firstly; note that the Windows printing system has been redesigned in Windows Vista and beyond. While the old system still works in WIndows 7 and 8, I am unsure of exactly how usable it is in Windows 10. In Windows 10 everything goes via XPS, and I think (could be wrong) that PostScript is generated by going via XPS first.
Your first idea doesn't sound plausible to me. How can you have a printer (and allow your application to print to it) if you don't have a printer driver ? Even if you could do so, why would you create PostScript from GDI just to send it to Ghostscript and have it create PDF ? It would be far more reasonable to create PDF directly.
In the second case I don't see how adding a new local port would help you at all. Ports are simply where the output of the printer driver is directed. What a Port Monitor (RedMon is a Port Monitor) does is redirect the data stream sent to the port, and 'do something' with it. In the case of Ghostscript + RedMon the 'something' is create a PDF file.
I'm unclear why you don't want to use RedMon, given that you are apparently happy with using Ghostscript. However, if you really don't want to do that then write your own Port Monitor. The process is documented in the Windows Device Driver Development Kit and isn't especially hard. If you get stuck you can even look at the RedMon code as a guide. For example, see here

copy clipboard of linux into windows clip-board in network

I am writing a small tool, that copies clipboard of linux into windows clip-board. Let me take an example, both linux and windows in network connection. I copy something in linux to clip-board, then when I press some keys in windows lets take CTRL+ALT+v what is copied in linux should print in linux.
What I thought is executing some script in linux from windows through ssh connection. That script shall copy the clip-board into some file in windows, then windows shall put the file content into windows clip-board.
My problem is connection with linux from windows and executing the script. How can I achieve this ?
And please share if you have any better idea to do this.
Thanks a lot :).
There is a free, cross-platform, open-source program called Synergy that does exactly what you are describing (and more), and I have tested it with a Windows/Linux connection. You could take a look at the source code and see how the clipboard functions are implemented, or it might fit your needs already.

How to interact with the console (input/output) running a Perl program on "Windows Power Shell ISE"?

I have a certain Perl program that I need to run on Windows 7 "Power Shell ISE" (since the regular MS Windows console does not support many Unicode fonts, and PS-ISE does, and I need to process Unicode files on Windows, using Perl).
When running a Perl program from the regular cmd console, you go, for example, "Perl hello.pl"; the program runs, and if you print something, let's say print "Hello world\n"; it gets printed in the cmd box.
How can I do it in PS-ISE? In PS-ISE, when I go: "Perl hello.pl" it hangs. PS-ISE says: "Running script/selection. Press Ctrl+Break to stop", but it doesn't print "Hello world".(Next, I also need to accept input from STDIN).Important note: it's "Power shell ISE", not: "Power Shell".
As I elaborated in another answer already, the PowerShell ISE does not support interactive Windows console applications.
Note also, that the console settings (and in particular the fonts) are totally irrelevant when processing Unicode text. Displaying is another matter. But processing doesn't sound like that to me.
Since you asked about Console in the mail, here it is, as a web search might have told you (and I thought I made my stance on personal mails originating from SO users clear).

How to make a Python PyQT program not open the command line in Windows

I have a Python program that is mostly complete, and there is one thing that I'd like to change, which may or may not be possible.
This program uses PyQT to display a GUI and I have it pretty much pinned up so I was wondering if I can make Python not open up a termianl when I open the program.
I am using Windows XP right now, but the machines it will run on will be Windows 7. I generally work with Linux, so I'm not terribly familiar with Windows.
If the terminal has to be there, it's no big deal, but I feel like it's extraneous at this point.
Thanks!
Use the python extension .pyw.
E.g program.pyw
This causes your program to be run with pythonw.exe instead of python.exe which suppresses the terminal.

64-bit Windows 7 fopen prn

I am using my antique Borland Builder 5 with Windows 7 64-bit.
fptr=fopen("\prn","wb") fails. "prn", "prn:" also fail.
fptr=fopen("HP8 lj4","wb") succeeds. But doesn't print anything. The "HP8 lj4" is the name of a printer; in control panel, or via "net view hp8gig".
The console command { print /D:"HP8 lj4" shopping.ln } says "shopping.ln is currently being printed" -- but doesn't print anything either.
Of course I print things on that printer all the time. My beautiful ASCII TSE editor can do it.
Anybody know how to print from a console program in Windows 7?
//Monday, September 12, 2011 5:29 pm. Later I realized my "HP8 lj4" was printing to a file with that name. And I tried to comment here, but apparently failed....
Tue 9/13/2011 4:05 pm. The way to print from a console "prn"-oriented program in Windows 7 et al is "net use lpt1: \hp8gig\UrPrinter /PERSISTENT:YES". "UrPrinter" must be "shared". And that's all it takes; my wretched little console program prints fine now. One reason I got confused, aside from natural talent, was that the desired printer was local. It was attached to the computer -- but via USB. After doing this, a command-line like "copy file /b prn" prints.
I knew this before apparently -- I found it in a "printnet.bat" file I wrote, to access a network printer from another computer -- but obviously I forgot.
So the code from the web site I mentioned before was broken -- a few typos -- and even when it worked, didn't. Which is to say, I still don't know how to programmatically do the "net use" thing.
Mon 9/12/2011 5:49 pm. OK the general problem is how to redirect the revered &
antique "PRN" device on a windows 7 machine to something useful. I don't know
how to do that. A fellow at
http://comsci.liu.edu/~murali/win32/NetworkPrint.htm has some code which looks
like it might make PRN print again, but his plan also suggested trying the
network name of my desired printer in my silly program -- and that works.
I.e., I stuck in code like
if (stricmp(name,"prn")==0) {
name =
#if W7
"\\\\hp8gig\\HP8 lj4"
#endif
}
I can make something more sophisticated with an environment variable, or
perhaps I'll figure-out the fellow's PRN thing....

Resources