Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Perl Program Exits.

by Xelium (Initiate)
on Aug 03, 2012 at 06:23 UTC ( #985160=perlquestion: print w/ replies, xml ) Need Help??
Xelium has asked for the wisdom of the Perl Monks concerning the following question:

When I run my perl file, it quickly shows the screen and exits. Can someone tell me why it does this and maybe how to fix it? Am I missing some type of end code? I know this is basic, but can anyone help me out?

Comment on Perl Program Exits.
Re: Perl Program Exits.
by tobyink (Abbot) on Aug 03, 2012 at 06:34 UTC

    Are you running this on Windows, by double clicking a file icon? If I recall correctly Windows automatically closes the command-line window once the program has finished running when a program has been started this way, but there is a way to change that behaviour somewhere by right clicking the file and going into its properties.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: Perl Program Exits.
by BrowserUk (Pope) on Aug 03, 2012 at 06:48 UTC

    Try adding this close to the top of your program:

    END{ sleep 1e9; }

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Thank you, this worked, I couldn't find how to edit it in properties though.
        I couldn't find how to edit it in properties though.

        I'm not aware of any mechanism using the properties to prevent the window closing when the program finishes.

        My 'fix' simply delays the program finishing for a very long time or until you manually close the window.

        There is wperl.exe which can do something similar I think, but I've never used and can't find any documentation on how to use it.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

        You "could" setup this association
        assoc .plA=PerlScriptAnnoying FTYPE PerlScriptAnnoying=cmd.exe /k "perl.exe" %1 %* set pathext=%pathext%;.PLA
        and that would keep cmd.exe open after perl is finished (/k means keep cmd open)
Re: Perl Program Exits.
by nemesdani (Friar) on Aug 03, 2012 at 07:50 UTC
    I always run my perl files from a command window. Thus this window will not close. And I can enter any parameters. And I am oldschool :).


    I'm too lazy to be proud of being impatient.

      So many possibilities :-)

      I run mine from a .bat-File. That way I can control the perl and the libraries I want to use. And using pause will prevent the exit-problem of the OP.

      Example: (objcmp.bat)

      D:\tools\perl\bin\perl -Id:/tools/perl/lib -w objcmp.pl D:\releases\12 +113129 YES > xxx.txt pause

Re: Perl Program Exits.
by 2teez (Priest) on Aug 03, 2012 at 08:00 UTC

    I know this is basic, but can anyone help me out?

    Here is something you can do, using the 'diamond' operator <> .
    Since, "<>" expect an input from the keyboard, your program doesn't exit until you press ENTER key on the keyboard. Therefore, just pressing the ENTER key exit your program.
    Here is an exmple:

    #!/usr/bin/perl use warnings; use strict; foreach(0..9){ print $_,$/; } <>; # press Enter to quit

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://985160]
Approved by tobyink
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-09-20 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (158 votes), past polls