in reply to Console Window Minimized

# Listing 3. Code to Hide a Perl Console Window use Win32::API::Prototype; ApiLink( 'kernel32.dll', 'HWND GetConsoleWindow()' ) || die; ApiLink( 'user32.dll', 'BOOL ShowWindow( HWND hWnd, int iCommand )' ) || die; $hWnd = GetConsoleWindow(); print "About to hide the window...\n"; sleep( 1 ); # Hide the window. # BEGIN CALLOUT A ShowWindow( $hWnd, 0x00 ); # END CALLOUT A my @results=`ipconfig \all`; print @results; sleep( 5 ); print "About to restore the window...\n"; # Restore the window. # BEGIN CALLOUT B ShowWindow( $hWnd, 0x04 ); # END CALLOUT B print "Restored!\n";

May be it will be useful.

This code comes from Dave Roth's article Progressive Perl for Windows: Hiding the DOS Box and Other Magical Tricks

Replies are listed 'Best First'.
Re^2: Console Window Minimized
by slloyd (Hermit) on Sep 20, 2004 at 16:14 UTC
    You misread the question. I already know how to hide the console that launched the perl process. How do you hide the console window that is launched when perl calls a dos command and at the same time, capture its output?
      No, I do not misread. A console application (launched from a script) requires a console window. If the script is running in console already then new applicaion uses that console. If the script is executed by wperl (without console window) then the system creates new console window for that application.

      I meant that you can start your script in console, then hide it with Windows API function, then call any console application -- all of them will use the hidden console.

      I've tested the code before post it. It works as desired.

      Also I think that Win32::API::Prototype module is obsolete, you can use pure Win32::API instead of it.

        Thanks for the clarification. I will give it a try.
        Also I think that Win32::API::Prototype module is obsolete, you can use pure Win32::API instead of it.

        Please clarify?


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
        This seems to work except for one catch. When I reboot the computer with the application running Windows kicks an error saying it is unable to end the program. I added the following code to my program but it did not help. When I compile my code with perl2exe using the -gui option, my program exits properly but I get flashing dos windows. Is there a way around this...?
        $SIG{INT}=\&ctrlc; $SIG{HUP}=\&ctrlc; $SIG{QUIT}=\&ctrlc; #Quit $SIG{TERM}=\&ctrlc; #Terminate $SIG{PIPE}='IGNORE'; sub ctrlc{exit;}