Windows: stop automatic closing of the terminal
- From: "tuser" <tuser3@xxxxxxxxx>
- Date: 20 Aug 2006 11:34:01 -0700
I had longstanding problems with Activestate Perl under Windows XP
which closed the terminal window too early. Now I have found a solution
and I hope you don't mind if I share it with the group.
Problem:
======================================================
My Activestate perl was basically working under Windows XP, but there
was one thing which annoyed me when I wanted to run a simple perl
program by double-clicking on it: the terminal window is closed almost
instantly, so there is no chance to read the output.
I thought I should add something which prompts for a keystroke at the
end of every perl program, but before the terminal is closed. Of
course, this should only apply if the perl program was invoked by
double-click, I didn't want to be prompted for a keystroke if I ran my
perl-program from the command line of an already open terminal session.
Solution 1:
======================================================
At first I stumbled upon "Win32::Die"
http://search.cpan.org/~accardo/Win32-Die-0.03/lib/Win32/Die.pm
Looking at the documentation, this module detects if a program was
double-clicked, or run from a command line. The DOS window remains put
until you close the window or hit a key.
"Great...", I thought. "...let's try it out".
I tried it out, and it worked
But there were two things that I did not like with "Win32::Die":
First, every perl-program had to be modified to add an additional line
"use Win32::Die;"
And secondly, if my perl program happened to have a compile-error
(...and believe me, I get them quite a lot in my programs...), the
module "Win32::Die" can not prompt me for a keystroke, so any messages
were lost when I double-clicked on a perl program with compile errors
in it.
Solution 2:
======================================================
So I came up with a second solution:
For every existing perl-program (for example "prog.pl"), I added
another wrapper program ("wrap_prog.pl"), which consisted of only 2
lines:
system('prog.pl');
system('pause');
This worked fine: every perl-program which was run by double-clicking
on its wrapper-program "wrap_prog.pl" was followed by a prompt, even if
the program had compile-errors.
However, if I wanted to run the program from a command line, I had to
run a different program "prog.pl", so I was not prompted for a
keystroke.
Also, I found it very tedious having two "*.pl" for each program.
Solution 3: (final)
======================================================
So finally, I came up with a solution wich worked very well for me:
Under C:\Script\, I created a simple *.bat file: "perlprompt.bat":
===
@echo off
perl %1
pause
(I suppose this could have equally been a "perlprompt.pl" file, but I
have not yet tried it)
Anyway, I then I fired up Windows Explorer and selected menu "Tools" /
"Folder Options..." / tab "File Types".
In the "Registered File Types" frame, I scrolled down and selected the
".PL" entry.
Then I pressed the "Advanced" button which opened another small window
("Edit File Type").
Then, in the frame "Action" of that small window, I highlighted the
already existing line "Open" and pressed the "Edit..." button. (I
suppose, if there is no existing line "Open", one can equally create a
new action "Open" by hitting the "New..." button, but I have not tried
this yet)
Then, in the box "Application used to perform action:",
I changed: C:\Perl\bin\perl.exe" "%1" %*
into: C:\Script\perlprompt.bat" "%1" %*
Then I hit the "OK" button and that's it !
Now I am prompted for a keystroke for every perl program that is run by
double-click, even if it has compile-errors. Also, there is no need to
modify the program or to add wrappers for each existing program.
Finally, if I run the perl program from the command line, I am not
prompted for a keystroke.
That's it, I hope my story can be useful.
.
- Prev by Date: String or numbers in AoA?
- Next by Date: Re: String or numbers in AoA?
- Previous by thread: String or numbers in AoA?
- Next by thread: Programming WAP pages
- Index(es):