Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Hiding DOS windows that accompany TK

by jbbarnes (Novice)
on Dec 08, 2008 at 10:06 UTC ( #728885=perlquestion: print w/replies, xml ) Need Help??

jbbarnes has asked for the wisdom of the Perl Monks concerning the following question:

Elder Monks,

I have designed a nice little GUI app with ActiveState & TK. It runs well under both Linux & Win32. But when I run it under Win32, an unsightly DOS window pops up just underneath the GUI interface.

The title bar of the window is the full path of the perl.exe executable. I have looked for command-line options and various other tricks to hide the window. No luck. I would prefer to see no window at all, but would settle for at least having it minimized. Is there any way to do that?

Thank you.

Replies are listed 'Best First'.
Re: Hiding DOS windows that accompany TK
by marto (Cardinal) on Dec 08, 2008 at 10:16 UTC
Re: Hiding DOS windows that accompany TK
by Erez (Priest) on Dec 08, 2008 at 13:12 UTC
    I borrowed this from the Perl Cookbook a while ago:
    use strict; use warnings; use Win32; use Win32::Process; my $program = shift @ARGV or die "Usage: loader.pl program\n"; Win32::Process::Create($Win32::Process::Create::ProcessObj, 'd:\strawberry\perl\bin\perl.exe', #or wherever perl.exe is locate +d "perl.exe $program", 0, DETACHED_PROCESS, '.') or die print_error(); sub print_error { return Win32::FormatMessage( Win32::GetLastError() ); }

    "A core tenant of the greater Perl philosophy is to trust that the developer knows enough to solve the problem" - Jay Shirley, A case for Catalyst.

      Did that actually work for you? I tried something similar from the Cookbook, although it may have been an earlier edition and couldn't get it to work. However after trolling the net, I found that by adding
      $Win32::Process::Create::ProcessObj -> Resume();
      after the code that you have, did the trick.


      To disagree, one doesn't have to be disagreeable - Barry Goldwater

        It did and it does. I don't recall whether this is lifted verbatim off the cookbook or whether I altered anything. I placed that code in a file a year or two ago, and have been only updating the path, and calling it.

        "A core tenant of the greater Perl philosophy is to trust that the developer knows enough to solve the problem" - Jay Shirley, A case for Catalyst.

Re: Hiding DOS windows that accompany TK
by syphilis (Bishop) on Dec 08, 2008 at 10:46 UTC
    If you launch your app with wperl.exe (which is also in your perl/bin folder), instead of perl.exe, then that DOS window might not get created ... not sure ...

    Cheers,
    Rob

      wperl is the correct answer. It runs perl as a "WINDOWS" subsystem application. Normally perl runs as a "CONSOLE" subsystem application.

      Without a console, your perl script will not have a proper STDIN, STDOUT, or STDERR. Perl does the best it can to paper over the problems, but doing IO redirection with child processes can be troublesome.

      exetype.bat in the perl/bin directory converts the console version of perl into a WINDOWS subsystem app.

      See the MSDN article on the SUBSYSTEM linker option for MSVC for a tiny bit of info.


      TGI says moo

Re: Hiding DOS windows that accompany TK
by BrowserUk (Pope) on Dec 08, 2008 at 11:37 UTC
Re: Hiding DOS windows that accompany TK
by CountZero (Bishop) on Dec 08, 2008 at 11:11 UTC
    I made a shortcut to the perl-script and in the properties of the shortcut I choose (under "run") minimized. The DOS window is still there but at least it is minimized and does not get in the way.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      use wperl
        One could indeed do that, but that means I have to change the Windows system-wide connection between the *.pl extension and perl.exe and most of the time (but not always) I like to see the DOS-window.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Hiding DOS windows that accompany TK
by srikrishnan (Beadle) on Dec 08, 2008 at 12:09 UTC
    I dont know what tool you are using to make exe from pl file.

    If you are using "PAR" module, then use the following syntax:

    pp --gui --icon Icon.ico -o sample.exe sample.pl

    I hope it would be useful for you

    Regards
    Srikrishnan
Re: Hiding DOS windows that accompany TK
by admiral_grinder (Pilgrim) on Dec 08, 2008 at 14:35 UTC

    I don't know about keeping it from showing up at all, but here is how you get ride of it when it does.

    Look at Win32::GuiTest. Try the FindWindowLike, ShowWindow, and IsWindowVisible functions:

    my @win = FindWindowLike( 0, "Super App", undef ); foreach my $win ( @win ) { ShowWindow( $win, SW_HIDE ) if ( IsWindowVisible( $win ) ); }
Re: Hiding DOS windows that accompany TK
by inoci (Scribe) on Dec 09, 2008 at 15:08 UTC
    i remember dealing with this a few years back, and solved it with the following :
    use Win32::Console; Win32::Console::Free();
    for my old apps that i used to maintain for both linux and windows i would do a comparison on $^O to see if the above code needed to be run. sadly, i cannot find an exact example, but it shouldn't be too hard to figure out.
Re: Hiding DOS windows that accompany TK
by jeepj (Scribe) on Dec 11, 2008 at 10:34 UTC
    Hello, as your script is running on Linux and Windows, you must check for the system. The following code should do the trick, I am using it. The dos window is showing up but disappear just after.
    BEGIN { if ($^O eq 'MSWin32') { require Win32::Console; Win32::Console::Free( ); } }
    PS: in fact, it's the same code as inoci, but with system check

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://728885]
Approved by marto
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2021-11-29 00:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?