- Although DOSBox offers printing support, the documentation is sparse and most articles refer to printing on a Windows host.
- Using DOSBox 0.7.4-3 I was unable to get printing working, so I'm using DOSBox-X instead.
- Using Ubuntu 20.04 and a fork of DOSBox called DOSBox-X, printing can be configured as follows.
This tutorial assumes you already have a raw printer setup and set as the default printer. For assistance setting up a default raw printer in Linux see here
- Install DOSBox-X
- Configure DOSBox-X to write to a physical file
- Write a script which listens on the physical file
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. If you're not on Ubutunt, see if DOXBox-X can be installed through other means. For Windows, MacOS or RPM users, DOXBox-X can be downloaded directly from the official dosbox-x site.
Although the recommendation for most tutorials is to configure DOSBox-X to print to a physical printer, I was unable to get this working on Ubuntu 20.04. Instead, I had to manually configure DOSBox-X to print to a file.
- Start DOSBox-X for the first time from Applications (or
dosbox-x
from Terminal) - Save a configuration file (the default location is your
$HOME
directory, this is fine)- Click: Main, Configuration Gui
- Click: Parallel
Forparallel1
, type:file append:prnout.txt
- Click: Configuration, Save (This is important!)
- Click: OK
Finally, write a bash script which listens on this prnout.txt file.
-
Create a file called
printlistener.sh
gedit printlistener.sh &
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
-
Make it executable:
chmod +x printlistener.sh
-
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.
DOSBox-X should have printer support which should be preferred, but due to the inability to get it to work, this workaround was created. It may be worthwhile to file this bug against the DOXBox-X code repository. The workaround uses a flat file and there are some grave limitations to printing using a flat file. Specifically, the above example may contain race conditions for when the file is partially written. Also, it relies on a relative file path, which may differ between environments. Please take this into consideration before using for critical services. Feel free to comment, fork or reuse this information in part or whole under public domain.
Apparently the
incron
tool can serve as the file watchdog in place of the more well-knowncrontab
/printlistener script.