Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

What everyone else has said so far is right - if you are reading from a pipe, then you cannot simply read from standard input again to read from the terminal.

However, this does not mean that all is lost. On many POSIX systems, you can find the name of the controlling terminal with POSIX::ctermid(); and then open and read from that.

#!/usr/bin/perl -w use strict; use Getopt::Std; use POSIX qw//; my $what; $| = 1; my @hosts; my %opts; while (<STDIN>) { chomp; push(@hosts, $_); } getopts(':dw', \%opts); $what .= ' bla' if $opts{'d'}; $what .= ' blabla' if $opts{'w'}; my $cterm = POSIX::ctermid(); if (! $cterm) {die "No controlling terminal to read prompt from!";} if (! open(CTERM, '<', $cterm)) { die "Couldn't open controlling terminal $cterm: $!"; } print "OK? [Y|n]>\n"; my $yesno = <CTERM>; chomp $yesno; exit 1 if $yesno =~ /^[nN]$/; print "Did not stop, sorry!\n";

Yes, I could have used STDIN there the second time, but I didn't so as to keep it clear where you were reading what from.

--
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

In reply to Re: No interactivity (prompt) after reading from pipe by fizbin
in thread No interactivity (prompt) after reading from pipe by svenXY

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 21:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found