Hello oh wise Perl monks. I have a question that I can not seem to find an answer to and I hope to take a sip from your fountain of knowledge.

I am currently writing a script that issues a system command and the command itself brings up a prompt like this after a few seconds

 Do you want to read the file? 1 for yes, 2 for no. (Default is 2)

My question is how would I issue my script to say yes once this comes up? I have tried with the following code, but seem to be having issues, primarily where the if statement does execute correctly, however the issuance of the automated user response is far to late. This appears to be due to the script returning user control and halts and waits for the user to enter anything, including just pressing the enter key. Any help is appreciated!

$output = `Command foo`; print $output; if ($output = ~/Do you want to read the file?/) { `2`; print "Correct String detected."; #detects that the if stateme +nt was executed. } else { print "Unsuccessful detection of String." #detects that the if + statements was unsuccessfully executed. }

In reply to automatically giving user input to a command line by tfredett

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.