Printing to a raw printer using DOSBox

Working article is here: https://gist.github.com/tresf/48183217173cdaef580b2cb1797a052c

Although DOSBox offers printing support, the documentation is sparse and most articles refer to printing on a Windows host.

Using Ubuntu 20.04 and a fork of DOSBox called DOSBox-X, printing can be configured as follows:


  1. Install DOSBox-X
  2. Configure DOSBox-X to write to a physical file
  3. Write a script which listens on the physical file

Install DOSBox-X


  1. Installing DOSBox-X on Linux is as simple as installing the snap: https://snapcraft.io/dosbox-x.  This can be launched with Ubuntu Software center.

    Note: For Windows, MacOS or RPM users, DOXBox-X can be downloaded directly from the official site.

Configure DOSBox-X to write to a physical file

Although the recommendation for most tutorials is to configure DOSBox to print to a physical printer, I was unable to get this working on Ubuntu 20.04.  Instead, I had to manually configure DOSBox to print to a file.

  1. Start DOSBox-X for the first time from Terminal

    dosbox-x
  2. Save a default configuration file (the default location is your $HOME directory, this is fine)
    • Main, Configuration Gui
    • Parallel
    • For parallel1, type:
      file append:prnout.txt
    • Configuration, Save (This is important!)
    • OK

Write a script which listens on the physical file

Finally, write a bash script which listens on this prnout.txt file.

  1. Create a file called printlistener.sh

    gedit printlistener.sh &
  2. Paste the following


    #!/bin/bash


    # File to look for
    TOPRINT=~/prnout.txt

    printf "Waiting for content at $TOPRINT\n"

    while [ true ]; do
      printf "."
      sleep 1 # one second
      if test -f "$TOPRINT"; then
        printf "\n[$(date)] Sending $(wc -c "$TOPRINT" | awk '{print $1}') bytes\n"
        lpr -o raw "$TOPRINT" && rm "$TOPRINT"
      fi
    done
  3. Make it executable:

    chmod +x printlistener.sh
  4. Start the listener

    ./
    printlistener.sh


Last, print from the DOS application and it will send to your printer.  Note, this will send content in a text format.  This may be undesirable for certain printers.

For assistance setting up a default raw printer in Linux see here: https://github.com/qzind/tray/wiki/setting-up-a-raw-printer-in-ubuntu-linux

Comments

Popular posts from this blog

iPod Touch iPhone 3G Ubuntu 9.10 in 5 minutes

Pidgin - Microsoft Office Communicator

Netflix + Ubuntu