After asking this question, I delved a bit deeper and was able to solve it by using a nasty hack:
use Win32API::File qw(createFile);
use Win32::Console;
my $handle = createFile('CONOUT$', 'rwke') or die "conout\$: $^E\n";
# my $console = new Win32::Console($handle) or die "new console: $^E\n";
my $console = bless {handle => $handle}, 'Win32::Console';
I looked at the code for the new()
function inside Win32::Console
and saw that it just creates a hash containing the handle to a console. If the parameter specifies stdin/stdout/stderr, it just retrieves the associated handle otherwise it creates a new console screen buffer and uses the handle for that.
So I just manually created the Win32::Console
object containing a handle to the console returned by CreateFile.
So now perl myscript.pl > nul 2> nul < nul
will write blah blah
on the screen immediately below the command line.
I'll accept a better answer if someone comes up with one.