문제

Suppose in a CMD (Windows 7) batch file I want to print the contents of a directory. I'd expect to do something like this:

dir | print

But this doesn't work, because print apparently requires a file. Is there an intelligent one-liner to do this? (preferably not involving file manipulation)

도움이 되었습니까?

해결책

You can do the following

dir > f && print f

If you get the error Unable to initialize device PRN, then you will need to specify the printer using the /D: switch with the print command. You can also delete the file after running the command if you want.

dir > f && print f /D:"Printer Name" && del f

To do it without outputting to a file you can just redirect the command output to a shared printer.

dir > \\share\printer

To get a list of shared printers use PowerShell

get-WmiObject -class Win32_printer | ft name, systemName, shareName

I prefer outputting to a file then printing the file, so the name of the print job has some relevance to the actual content.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top