home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomePerl CookbookSearch this book

15.17. Removing the DOS Shell Window with Windows Perl/Tk

Problem

You have written a Perl program for the Windows port of Perl and Tk, but you get a DOS shell window every time you start your program.

Solution

Start your program through another Perl script. The Perl script in Example 15.8 is a loader that starts realprogram without the DOS window.

Example 15.8: loader

#!/usr/bin/perl -w
# 

loader - starts Perl scripts without the annoying DOS window
use strict;
use Win32;
use Win32::Process;

# Create the process object.

Win32::Process::Create($Win32::Process::Create::ProcessObj,
    'C:/perl5/bin/perl.exe',            # Whereabouts of Perl
    'perl realprogram',                 #
    0,                                  # Don't inherit.
    DETACHED_PROCESS,                   #
    ".") or                             # current dir.
die print_error();

sub print_error() {
    return Win32::FormatMessage( Win32::GetLastError() );
}

Description

This program isn't as cryptic as it looks. You get the DOS box because your Perl binary was compiled as a console application. It needs a DOS window open to read STDIN and write STDOUT. This is fine for command-line applications, but there's no need for it if you're using Tk for all your user interaction.

This loader uses the Win32::Process module to run the real program in a new process. The process is detached from the current one, so when the loader ends, its DOS window will go away. Your real program will continue on in glorious freedom without the shackles of the past.

Should trouble strike and your real program not load, the loader dies with the Windows error message.

See Also

The documentation for the Win32::Process module, which is included with distributions of Perl destined for Microsoft systems


Previous: 15.16. Responding to Tk Resize Events Perl Cookbook Next: 15.18. Program: Small termcap program
15.16. Responding to Tk Resize Events Book Index 15.18. Program: Small termcap program

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.