you have several options:
- use the wperl.exe provided with ActivePerl to run your script. this is a copy of perl.exe that just doesn't create a console window at all. remember, however, that you have no STDIN/STDOUT/STDERR, so you can't even catch errors. be sure your script is totally bulletproof before calling it with wperl.exe. also note that more info about this method are available here.
- use Win32::GUI and the following lines:
my $hw = Win32::GUI::GetPerlWindow();
- use Win32::API, but this requires a lot of work:
what the above code does is exactly what Win32::GUI does (a nasty trick I've found in the MSDN documentation :-).
use Win32::API 0.20;
# just for completeness...
use constant SW_HIDE => 0;
use constant SW_SHOWNORMAL => 1;
# the API we need
my $GetConsoleTitle = new Win32::API('kernel32', 'GetConsoleTitle', 'P
my $SetConsoleTitle = new Win32::API('kernel32', 'SetConsoleTitle', 'P
my $FindWindow = new Win32::API('user32', 'FindWindow', 'PP', 'N');
my $ShowWindow = new Win32::API('user32', 'ShowWindow', 'NN', 'N');
# save the current console title
my $old_title = " " x 1024;
$GetConsoleTitle->Call( $old_title, 1024 );
# build up a new (fake) title
my $title = "PERL-$$-".Win32::GetTickCount();
# sets our string as the console title
$SetConsoleTitle->Call( $title );
# sleep 40 milliseconds to let Windows rename the window
# find the window by title
$hw = $FindWindow->Call( 0, $title );
# restore the old title
$SetConsoleTitle->Call( $old_title );
# hide the console!
$ShowWindow->Call( $hw, SW_HIDE );
# sleep one second, then show the console again
$ShowWindow->Call( $hw, SW_SHOWNORMAL );
King of Laziness, Wizard of Impatience, Lord of Hubris