# Output a text to the standard printer

**URL:** <https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865>\
**Category:** Uncategorized\
**Created:** [November 27, 2023, 12:41pm UTC](https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865 "2023-11-27T12:41:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![JBaben](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@JBaben](https://fortran-lang.discourse.group/u/JBaben)\
**Post date:** [November 27, 2023, 12:41pm UTC](https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865/1 "2023-11-27T12:41:13Z")

</div>

Hello,  
I would like to read the contents of a text file and output the text line by line to the standard printer (OS = WINDOWS 11)  
Compiler: gfortran, ifort  
Unfortunately, I couldn’t find a corresponding command, function or example code on the Internet.  
Kind Regards  
Juergen

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [November 27, 2023, 12:48pm UTC](https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865/2 "2023-11-27T12:48:40Z")

</div>

What do you mean by “the standard printer” ? The default printer of Windows ? Or the standard output in the terminal ?

---

<div class="post-metadata">

**Author:** ![feenberg](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@feenberg](https://fortran-lang.discourse.group/u/feenberg)\
**Post date:** [November 27, 2023, 1:06pm UTC](https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865/3 "2023-11-27T13:06:28Z")

</div>

I believe at one time one could just open a file named “prn” or “lpt1” and write to it:

open(file=‘prn’,unit=6)  
write(6,\*) ‘hello,world’

but apparently it is harder now. See:  
[https://www.frazerhelp.com/help-manual/lpt-ports-and-windows-10.htm](https://www.frazerhelp.com/help-manual/lpt-ports-and-windows-10.htm)

---

<div class="post-metadata">

**Author:** ![JBaben](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@JBaben](https://fortran-lang.discourse.group/u/JBaben)\
**Post date:** [November 27, 2023, 1:08pm UTC](https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865/4 "2023-11-27T13:08:56Z")

</div>

Hello,  
I mean naturally the default printer which is connected to the WINDOWS PC via cable or WLAN.  
The output on the terminal is easy, there is the “write” or “print” command for that.  
Kind Regards  
Juergen

---

<div class="post-metadata">

**Author:** ![JBaben](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@JBaben](https://fortran-lang.discourse.group/u/JBaben)\
**Post date:** [November 27, 2023, 1:52pm UTC](https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865/5 "2023-11-27T13:52:37Z")

</div>

Hello,  
thank you for your fast answer.  
with:

```auto
open(file='lpt1',unit=6) ! line 8
write(6,*) 'Hello, World!'

```

I get the following message:

```auto
At line 8 of file print.f90 (unit = 6)
Fortran runtime error: Cannot open file 'lpt1': Permission denied
Error termination. Backtrace:
Could not print backtrace: libbacktrace could not find executable to open
#0 0xf3dc04ba
#1 0xf3db7e21
#2 0xf3db3178
#3 0xf3dbbd07
#4 0xf3db3da7
#5 0xf3d91769
#6 0xf3d917ff
#7 0xf3d913ad
#8 0xf3d914e5
#9 0x1b1c26ac
#10 0x1c12aa67
#11 0xffffffff

```

I can print a test-page.  
Kind Regards  
Juergen

---

<div class="post-metadata">

**Author:** ![sblionel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/sblionel/32/853_2.png) [@sblionel](https://fortran-lang.discourse.group/u/sblionel)\
**Post date:** [November 27, 2023, 2:06pm UTC](https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865/6 "2023-11-27T14:06:32Z")

</div>

There is no standard way to do this. Intel Fortran supports an extension DISPOSE=‘PRINT’ in its OPEN and CLOSE statements, but the documentation says:

> On Windows\*, PRINT and the PRINT part of PRINT/DELETE do not use the system PRINT command. One of the following occurs:
> 
> - If you set the environment variable FOR\_DEFAULT\_PRINT\_DEVICE to a print device, the Fortran runtime will copy the file to that device.
> - Otherwise, the Fortran runtime will copy the file to a new file named “PRN-FILE”. In this case, you will need to do the actual printing

While you could associate a printer with the LPT1 device with the `net use` command, and then issue a `print` command, but that may or may not be useful.

If you’re using Intel Fortran, there is a worked sample called WinPrint in the Miscellaneous folder of the [samples bundle](https://software.intel.com/content/www/us/en/develop/download/776976.html) that allows you to print a text file directly to any defined printer. There is also WinPrintDirect to print non-text files that the printer may understand, such as .PS or .PRN.

---

<div class="post-metadata">

**Author:** ![Paddy](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/paddy/32/4045_2.png) [@Paddy](https://fortran-lang.discourse.group/u/Paddy)\
**Post date:** [November 27, 2023, 3:06pm UTC](https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865/7 "2023-11-27T15:06:56Z")

</div>

Hoever ugly, you could do this:

program print  
call execute\_command\_line(“notepad/p output.txt”)  
end program print

Microsoft doesn’t like you using Fortran. They defend their patch every way they can.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [November 27, 2023, 3:42pm UTC](https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865/8 "2023-11-27T15:42:59Z")

</div>

> [@JBaben](#):
>
> The output on the terminal is easy, there is the “write” or “ **print** ” command for that.

This is precisely why I wanted you to disambiguate your question: to avoid any long answer about printers in the case your question would have had a straightforward answer about the terminal (and I can’t know if you are a beginner or not).

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [November 27, 2023, 3:50pm UTC](https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865/9 "2023-11-27T15:50:14Z")

</div>

> [@Paddy](#):
>
> `call execute_command_line(“notepad /p output.txt”)`

This is indeed a pragmatic approach…

> [@Paddy](#):
>
> Microsoft doesn’t like you using Fortran. They defend their patch every way they can.

This issue would be the same with any other language that is not printer-aware.

---

<div class="post-metadata">

**Author:** ![JBaben](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@JBaben](https://fortran-lang.discourse.group/u/JBaben)\
**Post date:** [November 27, 2023, 4:37pm UTC](https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865/10 "2023-11-27T16:37:44Z")

</div>

Hello,  
thanks for the Fortran code “print”.

```auto
program print
call execute_command_line('notepad/p output.txt')
end program print

```

It works like this, I think the “notepad” program needs to be installed.  
Kind Regards  
Juergen

---

<div class="post-metadata">

**Author:** ![Paddy](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/paddy/32/4045_2.png) [@Paddy](https://fortran-lang.discourse.group/u/Paddy)\
**Post date:** [November 27, 2023, 6:08pm UTC](https://fortran-lang.discourse.group/t/output-a-text-to-the-standard-printer/6865/11 "2023-11-27T18:08:27Z")

</div>

If you have a Windows box, notepad is already installed.
