List Info

Thread: dos cmd window woes




dos cmd window woes
country flaguser name
United States
2007-02-28 16:44:40
When building applications using PerlApp, I have a choice
to build them without an associated DOS console window using
--gui.


However, if the application I built ever does something
like
either of the following:

system($my_other_program);

or

my $fh = new FileHandle($my_pipeline_command)


A dos command window suddenly pops up for the duration of
the executed subprocess and then goes away.


Since my application needs to regularly invoke other
executables, I have gotten in the habit of building it
without the --gui option so I won't get a sequence of
dancing console windows.


However, without the --gui option I of course get one
persistent command window for the duration of my
application's
run.

Just today, I finally figured out a workaround (sort of) for
this
problem.

I inserted the following ugly hack at the top of my
main.pl:

=======================================
         
my $perl_win32_window;
BEGIN {  
    if ($^O =~ /mswin/i) {
        # prevent the appearance of a DOS CMD window
associated with
        # the perl application
        use Win32::GUI;
        $perl_win32_window = Win32::GUI::GetPerlWindow();
        # however, when we are actually in the process of
building
        # our perl application with PerlApp, we do not want
to
        # hide the window so use an environment variable to
communicate
        # this fact from the batch file that runs PerlApp
        if (!$ENV) {
            no strict 'subs';
            Win32::GUI::Show($perl_win32_window,SW_HIDE);
        }   
    }   
}   

END {
    if ($^O =~ /mswin/i) {
        Win32::GUI::Show($perl_win32_window);
    }   
}   

================================

Unfortunately, Win32::GUI is not available from ActiveState
right now so anybody else who wants to apply this hack
should know that you'll need to get it from bribes.org
with this command:

ppm install http://w
ww.bribes.org/perl/ppm/Win32-GUI.ppd


This is a partial solution but it has the drawback that the
DOS command window shows up for several seconds when the
user first clicks on my application's icon and then it
disappears.  I would prefer if I could get it to go
away earlier.  I have a feeling that the reason for the
delay is startup delay in my packaged perl process while
the various components are being extracted to temporary
directories.


Is there any other way to solve this problem?

Is there some way that the bootstrap code generated by
PerlApp could be directed to do the window hide so that
it will happen earlier in the process?

- Steve Madere
_______________________________________________
PDK mailing list
PDKlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

Re: dos cmd window woes
country flaguser name
United Kingdom
2007-02-28 16:54:39
Hi,

using perl 5.8?

You need

Win32::SetChildShowWindow( Win32::SW_HIDE() );


I had similar hacks in place for a long time until I noticed
this in the
docs.


Mark



Steve Madere wrote:
> When building applications using PerlApp, I have a
choice
> to build them without an associated DOS console window
using --gui.
> 
> 
> However, if the application I built ever does something
like
> either of the following:
> 
> system($my_other_program);
> 
> or
> 
> my $fh = new FileHandle($my_pipeline_command)
> 
> 
> A dos command window suddenly pops up for the duration
of
> the executed subprocess and then goes away.
> 
> 
> Since my application needs to regularly invoke other
> executables, I have gotten in the habit of building it
> without the --gui option so I won't get a sequence of
> dancing console windows.
> 
> 
> However, without the --gui option I of course get one
> persistent command window for the duration of my
application's
> run.
> 
> Just today, I finally figured out a workaround (sort
of) for this
> problem.
> 
> I inserted the following ugly hack at the top of my
> main.pl:
> 
> =======================================
>          
> my $perl_win32_window;
> BEGIN {  
>     if ($^O =~ /mswin/i) {
>         # prevent the appearance of a DOS CMD window
associated with
>         # the perl application
>         use Win32::GUI;
>         $perl_win32_window =
Win32::GUI::GetPerlWindow();
>         # however, when we are actually in the process
of building
>         # our perl application with PerlApp, we do not
want to
>         # hide the window so use an environment
variable to communicate
>         # this fact from the batch file that runs
PerlApp
>         if (!$ENV) {
>             no strict 'subs';
>            
Win32::GUI::Show($perl_win32_window,SW_HIDE);
>         }   
>     }   
> }   
> 
> END {
>     if ($^O =~ /mswin/i) {
>         Win32::GUI::Show($perl_win32_window);
>     }   
> }   
> 
> ================================
> 
> Unfortunately, Win32::GUI is not available from
ActiveState
> right now so anybody else who wants to apply this hack
> should know that you'll need to get it from bribes.org
> with this command:
> 
> ppm install http://w
ww.bribes.org/perl/ppm/Win32-GUI.ppd
> 
> 
> This is a partial solution but it has the drawback that
the
> DOS command window shows up for several seconds when
the
> user first clicks on my application's icon and then it
> disappears.  I would prefer if I could get it to go
> away earlier.  I have a feeling that the reason for
the
> delay is startup delay in my packaged perl process
while
> the various components are being extracted to
temporary
> directories.
> 
> 
> Is there any other way to solve this problem?
> 
> Is there some way that the bootstrap code generated by
> PerlApp could be directed to do the window hide so
that
> it will happen earlier in the process?
> 
> - Steve Madere
> _______________________________________________
> PDK mailing list
> PDKlistserv.ActiveState.com
> To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs


_______________________________________________
PDK mailing list
PDKlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

RE: dos cmd window woes
country flaguser name
United States
2007-02-28 17:05:57
If your program doesn't require access to any of the output
from the
commands it starts, you can use Win32::Process to start
commands:

Win32::Process::Create(
	my $proc_obj,
	"$ENV\system32\cmd.exe",
	"cmd.exe /S /C "$cmd_line "",
	0,
	Win32::Process::CREATE_NO_WINDOW,
	$working_directory);
$proc_obj->Wait(&INFINITE);

You can also do paths directly to EXEs and modify the
command line as
required, etc.



If you want to avoid Win32::GUI, you can use the following
Win32::API
code that will do the same thing that Win32::GUI is doing
below:

use Win32::API 0.41;

{
my $call;
sub GetConsoleWindow {
	$call ||= Win32::API->new('kernel32',
				'GetConsoleWindow', '', 'I') or
			Carp::croak("Unable to connect to
GetConsoleWindow.");

	return $call->Call();
}
}

{
my $call;
sub ShowWindow {
	my($hWnd, $iCommand) = _;

	$call ||= Win32::API->new('user32',
				'ShowWindow', 'II', 'I') or
			Carp::croak("Unable to connect to
ShowWindow.");

	return $call->Call($hWnd, $iCommand) ? 1 : 0;
}
}

&ShowWindow(&GetConsoleWindow(), 0x00 );



The central problem is that for a process to have access to
the output
of another command, the process needs to have an associated
console
(although the console can be hidden or detached).  So far as
I know,
there is no way to mark an EXE (any EXE) so that it starts
with a hidden
console.  It would be a nice feature for PerlApp, however,
to have the
ability to build an EXE that would hide the console very
early on during
the execution (i.e. before it got all the Perl code ready to
execute).
Of course, really nice would be if it could somehow figure
out if it was
sharing a console with something else already (i.e. CMD.EXE
or some
other shell), in which case it wouldn't hide the console, or
if it was
the first EXE in the console, in which case it would know to
hide
itself.

--Toby Ovod-Everett

_______________________________________________
PDK mailing list
PDKlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )