Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

terminal control in MS

by RandomWalk (Beadle)
on Nov 25, 2003 at 04:59 UTC ( #309799=perlquestion: print w/replies, xml ) Need Help??

RandomWalk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I'm embarrassed to impose on your remarkably good will but I'm at a loss. I was reading the Llama at a MS Windows box. I got to "Getting User Input" and tried out the example:
$line = <STDIN>; print "That line of input was: $line";
When I run the script by 2-clicking on the cute pearl icon, the window displaying the output disappears faster than I can see whether the program succeeded or failed. Where do I learn how to control that window? In fact, I don't care so much about seeing what's sent to STDOUT as I do about having STDERR persist in a visible form when the program is launched in this way.

Thank you (again).

Replies are listed 'Best First'.
Re: terminal control in MS
by Roger (Parson) on Nov 25, 2003 at 05:04 UTC
    Many solutions -

    Solution 1
    Run it under the DOS prompt!

    Solution 2
    Add sleep(5); to the end of your script to wait for 5 seconds, long enough for you to inspect its output, whether it has failed or not.

    Solution 3
    having STDERR persist in a visible form when the program is launched in this way

    You could create a short-cut to your perl script, and modify the property of the shortcut to something like -
    C:\Perl\bin\Perl.exe C:\Perl-examples\example.pl 2> C:\Perl-examples\e +xample.log
    Which will redirect your STDERR to a log file when you double click on the short-cut.

    Solution 4
    Capture stuff printed to STDERR in your program, and pause at the end if anything was printed to STDERR. The perl script will only pause when there is something printed to STDERR.

    use IO::Capture::Stderr; my $capture = IO::Capture::Stderr->new(); $capture->start(); # start captured # your stuff here... print STDERR "...\n"; # STDERR is captured print "...\n"; # STDOUT is not captured # at the end $capture->stop(); # stop capture my @err = $capture->read; if ($#err >= 0) { # any captured error? print "$_" for @err; # print stderr to screen <STDIN>; # wait for input }
Re: terminal control in MS
by jweed (Chaplain) on Nov 25, 2003 at 05:29 UTC
    Or, you could have:
    ...code... <STDIN>; #Dummy input!

    In effect, this acts as a "press enter to leave button."

    I have stuck to this one since I programmed in Basic with getkey x to keep the terminal open.

    Fixed filehandle - 11/24


    Who is Kayser Söze?

      Possible Typo.. your <STTDIN> should be <STDIN>..?

      -----
      Of all the things I've lost in my life, its my mind I miss the most.
Re: terminal control in MS
by AcidHawk (Vicar) on Nov 25, 2003 at 05:31 UTC

    You could also put `pause`; at the end of your script which will stop the dos window closing and wait for you to "Press Any Key".

    -----
    Of all the things I've lost in my life, its my mind I miss the most.
Re: terminal control in MS (-Mouse)
by tye (Sage) on Nov 25, 2003 at 17:31 UTC

    See also -Mouse.

                    - tye
      I like how this place works! I can combine suggestions from Roger and -Mouse to get a window only for STDERR:
      package ouse; BEGIN { use IO::Capture::Stderr; $ouse::capture = IO::Capture::Stderr->new(); $ouse::capture->start(); } END { $ouse::capture->stop(); my @err = $capture->read; if ($#err >= 0) { print "$_" for @err; <STDIN>; } } 1;
      Thank you for taking the time.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2021-04-10 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?