print prn file from command prompt

"Command Prompt: Print PRN File in Steps"

By Robert Garcia
AD

Have you ever needed to print a PRN file from the command prompt? PRN files are often used to represent print jobs, and knowing how to print them from the command line can save you time and effort when automating tasks. In this guide, we'll explore the step-by-step process of printing a PRN file using the command prompt in Windows.

Before we dive into the process, it's essential to understand that PRN files are text files that contain important printing information. They are typically generated by software like Microsoft Word or Excel and saved with a .prn extension. Once created, these files can be printed using a variety of methods, including the command prompt.

Understanding the PRINT Command

The first step in printing a PRN file from the command prompt is understanding the PRINT command. This command is used to send a print job to a specified printer. In its simplest form, the PRINT command syntax looks like this:

AD
an image of a computer screen with the message ms - 1035 program displayed on it
an image of a computer screen with the message ms - 1035 program displayed on it
This Simple Trick Saves Command Prompt Output to a Text File
This Simple Trick Saves Command Prompt Output to a Text File
Download our cheat sheet with commands for CMD (free PDF)
Download our cheat sheet with commands for CMD (free PDF)

PRINT <file path>

Here's a breakdown of the syntax:

A Beginner's Guide to the Windows Command Prompt
A Beginner's Guide to the Windows Command Prompt
an image of a computer screen with the command panel open
an image of a computer screen with the command panel open
What is Command Prompt (CMD)?
What is Command Prompt (CMD)?
  • <file path>: This is the full path to the PRN file you want to print.

Basic Printing with PRINT Command

To print a PRN file, open the command prompt and navigate to the directory containing your PRN file using the CD (Change Directory) command. Then, use the PRINT command followed by the file name, like this:

PRINT example.prn

AD

Press Enter, and your PRN file should start printing. However, you might encounter an error if the default printer is not set or if you're using a shared printer. In the next section, we'll discuss how to handle such scenarios.

How to backup files and folders with Command Prompt in Windows [Guide] | dotTech
How to backup files and folders with Command Prompt in Windows [Guide] | dotTech
What is Command Prompt? Uses, Pros, Cons & More
What is Command Prompt? Uses, Pros, Cons & More
Unlock the Secret Tricks of CMD's 'Copy' Command: Your Key to File Prowess
Unlock the Secret Tricks of CMD's 'Copy' Command: Your Key to File Prowess
7 Common Tasks The Windows Command Prompt Makes Quick & Easy
7 Common Tasks The Windows Command Prompt Makes Quick & Easy
10 Command Prompt Tricks You Should Try in Windows 11
10 Command Prompt Tricks You Should Try in Windows 11
30 Hacks You Should Know...
30 Hacks You Should Know...

Specifying the Printer with the -P Switch

If you're having trouble printing because you don't have a default printer set, or you want to print to a specific printer, you can use the -P switch. The syntax looks like this:

PRINT -P <printer name> <file path>

AD

Here's how to use this syntax:

Command prompt command
Command prompt command
How to Use the Windows Command Prompt to Encrypt Files
How to Use the Windows Command Prompt to Encrypt Files
10 Command Prompt Tricks that Every Windows User Should Know - MiniTool
10 Command Prompt Tricks that Every Windows User Should Know - MiniTool
  1. Open the command prompt and run the following command to list all installed printers:
  2. PRINT /D

  3. Find the name of the printer you want to use from the list.
  4. Use the PRINT command with the -P switch, followed by the printer name and the file path. For example:
  5. PRINT -P My_Very_Unique_Printer example.prn

Printing PRN Files Using PowerShell

While the command prompt is a powerful tool, Windows PowerShell offers an even more streamlined way to print PRN files. The Start-Job cmdlet can be used to send a print job to the default printer. Here's how:

First, ensure that you have the printing management feature enabled in PowerShell. Run the following command:

AD

Add-WindowsCapability -Online -Name PrintManagement~~~~0.0.1.0

Once the feature is enabled, you can use the Start-Job cmdlet to print your PRN file:

Start-Job -ScriptBlock {Add-PrinterPort -Name "My_Host_Printer" -PrinterHostAddress "My_Host_Printer"} -ArgumentList "example.prn" | Wait-Job

In this command, replace "example.prn" with the path to your PRN file and "My_Host_Printer" with the name of your printer.

Using PowerShell Jobs and Threads for Printing

PowerShell jobs and threads can be used to print multiple PRN files simultaneously or sequentially. This can be particularly useful in automation scenarios. Here's a simple example:

  1. Create a list of PRN files you want to print:
  2. $PRNFiles = "C:\Path\To\File1.prn", "C:\Path\To\File2.prn", "C:\Path\To\File3.prn"

  3. Start a PowerShell job for each file:
  4. $jobs = @()

    foreach ($file in $PRNFiles) {

    $job = Start-Job -ScriptBlock { Start-Process -FilePath "C:\Windows\System32\PrintUI.exe" -ArgumentList "/Printer job" }

    $jobs += $job }

    }

  5. Wait for all jobs to complete:
  6. Wait-Job -Job $jobs

And that's it! Now you know how to print PRN files using the command prompt and PowerShell. Whether you're printing a single file or automating a print task, these methods provide efficient and flexible solutions.

printing and automation can greatly improve productivity, especially in office environments. So, the next time you need to print a PRN file, consider giving these command line methods a try. Happy printing!

AD