I have a printer, an HP DeskJet 712C, that I cannot print to via the shell "print" command in Windows 7 or Windows XP. I think this is because this particular printer is a "software" printer, something like a "software" modem. I am, however, able to print from Word, Notepad, and other programs. Is there some command line utility that I can use to print text files from?
Windows – Print text file from command line without shell “print” command
command lineprintingwindows
Related Solutions
The print
command uses the following synatx for the /d:
switch:
Specifies the printer on which you want to print the job. You can specify a local printer by specifying the port on your computer to which the printer is connected. Valid values for parallel ports are LPT1, LPT2, and LPT3. Valid values for serial ports are COM1, COM2, COM3, and COM4. You can also specify a network printer by its queue name (\ServerName\ShareName). If you do not specify a printer, the print job is sent to LPT1.
This means you can't use "CutePDF Writer"
as an argument.
There are two ways that should work:
Assign a COM port to your printer.
- Open Start → Control Panel → Devices and Printers.
- Right-click the CutePDF Writer and select Printer Properties.
- In the Ports tab, assign an unused port from
COM1:
toCOM4:
to your printer. If you chose, e.g.,
COM3
, print using the following command:print /d:COM3 test.txt
Share the printer.
- Open Start → Control Panel → Devices and Printers.
- Right-click the CutePDF Writer and select Printer Properties.
- In the Sharing tab, decide to share the printer and assign a share name to it.
If you chose, e.g.,
CutePDF
, print using the following command:print /d:\\%COMPUTERNAME%\CutePDF test.txt
Here's a way to do it with VBScript. Based on an answer provided by Jobbo.
The catch is, you must have a program registered as the default handler. In other words, if you just type the name of a file from the command line, it should open in the appropriate program. For example, if you pass the argument of "file.pdf" you must have a PDF viewer installed. If you want to print a Word document, you must have Word (I think a viewer should work, but I didn't test that) installed.
One more thing, some programs leave a window open (Adobe Acrobat Reader X) after the document prints. You could add logic to the script to close it, but I'll leave that up to you.
To use, type in cscript /nologo <name_of_script.vbs> <name_of_file_to_print>
where <name_of_script.vbs>
is the name of the program you save this under, and <name_of_file_to_print>
is the name of the file you would like to print. If the path contains spaces, enclose the argument in quotes.
Option Explicit
Dim shl, objFS
Dim fldr
Dim files,file
Dim file_to_print,wrk_folder
Set shl = CreateObject("Shell.Application")
Set objFS = CreateObject("Scripting.FileSystemObject")
if not wscript.Arguments.Count = 1 then
wscript.echo "Missing parameter!"
wscript.quit
end if
file_to_print = wscript.arguments(0)
file_to_print = objFS.GetAbsolutePathName(file_to_print)
wrk_folder = objFS.GetParentFolderName(file_to_print) & "\"
wscript.echo "Argument passed: " & wscript.arguments(0)
wscript.echo "Absolute file path: " & file_to_print
wscript.echo "Work folder: " & wrk_folder & vbcrlf
if objFS.FileExists(file_to_print) then
Set fldr = shl.Namespace(wrk_folder)
Set files = fldr.Items
For Each file in files
If LCase(file.Path) = LCase(file_to_print) Then
file.InvokeVerbEx("Print")
End If
Next
end if
Set shl = Nothing
Set fldr = Nothing
Set files = Nothing
Set objFS = Nothing
WScript.Quit
Best Answer
Try using the notepad command line switch /p? e.g.
http://answers.microsoft.com/en-us/windows/forum/windows_7-files/notepadexe-command-line-options/810760c1-a45a-4013-9544-1c1208e1b389