#!/usr/local/bin/perl -w use strict; use Test::More; use Getopt::Long; use Path::Tiny; my $realprint = 1; GetOptions( "realprint!" => \$realprint ); my $lpstat = "lpstat"; my $lpr = "lpr"; my $lpq = "lpq"; my( $default_printer ) = ( `$lpstat -d` =~ /: (.*)/ ); if( !defined $default_printer ) { die "Cannot find default printer"; } ok 1, "found default printer $default_printer"; SKIP: { if( !$realprint ) { skip "printing disabled", 1; } ok !lpq_busy(), "lpq empty"; my $temp = Path::Tiny->tempfile; $temp->spew( "This is a test." ); my $rc = system $lpr, "-P", $default_printer, $temp->absolute; is $rc, 0, "printing with $lpr"; ok lpq_busy(), "lpq busy"; while( lpq_busy() ) { sleep 1; } ok !lpq_busy(), "lpq empty"; } done_testing; sub lpq_busy { my $queue = `$lpq`; return $queue =~ /active/; }