Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Win32::Start Perl/Tk Script Without Annoying DOS Window

by PERLscienceman (Curate)
on Jul 03, 2003 at 23:48 UTC ( #271330=sourcecode: print w/replies, xml ) Need Help??
Category: GUI Programming
Author/Contact Info Jay Madigan (PERLscienceman) <>
Description: Have you ever wanted to run a Perl/Tk Script on Win32 without that pesky DOS window? This is the script. I found this in O'Reilly's Perl Cookbook, 1st Edition; Section 15.17, pp544-545. With a little tweak (their was an apparent typo in the book which caused it initially not to work). This script allows for an associated process, in this case,, to run without a DOS window. I found this script to be quite useful.
#!/usr/bin/perl -w

use strict;
use Win32;
use Win32::Process;

# Create the process object.

     "C:\\perl\\bin\\Perl.exe",              # Where Perl is located.
     "perl c:\\yourdir\\",    #
     0,                                      # Don't Inherit
     DETACHED_PROCESS,                       #
     ".") or                                 # current directory
     die print_error();                 # 
     sub print_error(){                 #
         return Win32::FormatMessage(Win32::GetLastError() );

$Win32::Process::Create::ProcessObj -> Resume();
Replies are listed 'Best First'.
Re: Win32::Start Perl/Tk Script Without Annoying DOS Window
by jsprat (Curate) on Jul 04, 2003 at 02:18 UTC
    Or if you use ActiveState Perl (maybe others?), Just use wperl.exe: wperl c:\yourdir\

    Update: I must not have been clear enough. In \Perl\bin there is an executable called wperl.exe that will run a script without opening the command prompt. It's simply a perl interpreter compiled as a Windows application rather than a console application.

    Try this - Create a shortcut on the desktop with wperl c:\path\to\ Double click it and see what happens. Look ma! No DOS box! ;)

    Update 2:podmaster informs me that wperl comes with all perls compiled on win32

      Excellent! This works perfectly!
      I will use this from now on under Win32.
      Thank you for the clarification.
      It makes things much simpler.
        Ah, but does anyone have any idea how to keep other processes from spawning new DOS windows? For example, I need to run cvs commands from a script and each time a run one I get a new DOS window. This happens whether I do a 'system( "cvs ..." )' or an 'open(CVS, "cvs ... |"); (For that matter, it happens on a `pwd`.)
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Win32::Start Perl/Tk Script Without Annoying DOS Window
by Anonymous Monk on Jan 24, 2006 at 01:36 UTC

    ActiveState also includes a "program" called PL2BAT that will transform your perl script into a batch file (so you can launch it directly w/o having to type perl ...).

    So, use PL2BAT on your program: pl2bat

    This creates yourTKscript.bat

    Now edit the bat file and change the perl line to start wperl -x -S %0 %*

    (This assumes you are using windows >= NT).

    This will cause the batch file to launch your TK script using the wperl executable (no DOS window) AND it will NOT wait for it to return (your TK script to exit) before it returns you to the DOS command prompt.

    Without the "start" on the front, your batch file would not return to the command line prompt until your TK script exited.

    - James

    Edit by GrandFather - replaced pre tags with code tags.

      On Windows Vista: I want to launch from the windows desktop with a double click and have it execute without the dos console window. If I create a myperlscript.bat that does: "c:\perl\bin\wperl.exe", the batch file itself seems to cause a dos console window to start up. As far as I know I can't change the file association on "" to use wperl.exe instead of perl.exe without causing all .pl files to change to wperl. I was also unable to create a shortcut on the desktop as described in a previous message above. Any hints?
        create a shortcut and NOT a batch file
        The easiest method is to create a new file association that executes wperl.exe

        To change which program starts when you double-click a file, follow these steps:

          Click Start, and then click Control Panel
          Click Folder Options
          Click File Types tab in Folder Options window and the full file types and their association will be listed
          Click New and type the File Extension (.wp) in the box and then click Advanced
          Choose an association for the file type (wperl.exe)
          Click OK and then Click Close
          Open the file again

        Here is the original Microsoft KB article

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://271330]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2023-12-10 17:27 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (40 votes). Check out past polls.