### 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, yourTKscript.pl, 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. Win32::Process::Create($Win32::Process::Create::ProcessObj, "C:\\perl\\bin\\Perl.exe", # Where Perl is located. "perl c:\\yourdir\\yourTKscript.pl", # 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(); 

Comment on Win32::Start Perl/Tk Script Without Annoying DOS Window
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\yourTKscript.pl.

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\script.pl. 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.)
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 yourTKscript.pl
[download]

This creates yourTKscript.bat

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

(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.

- James

Edit by GrandFather - replaced pre tags with code tags.

On Windows Vista: I want to launch myperlscript.pl 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 myperlscript.pl", 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 "myperlscript.pl" 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

Back to Code Catacombs

Create A New User
Node Status?
node history
Node Type: sourcecode [id://271330]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2015-05-29 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?