问题
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....
回答1:
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.
回答2:
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....
来源:https://stackoverflow.com/questions/7366280/64-bit-windows-7-fopen-prn