23

I am trying to execute a binary using the following command :

system("update");

After executing "update" command, the system prompts the following :

"Press ENTER to exit:"

How do I implement the above in my perl script?

1
  • Do you mean you want too implement a similar prompt or do you want to be able too respond too the prompt? Commented Nov 18, 2011 at 6:23

2 Answers 2

30
use strict;
use warnings;

print "Press ENTER to exit:";
<STDIN>;
Sign up to request clarification or add additional context in comments.

3 Comments

You may also have to set $| to something other than undef or 0. Otherwise, the output gets buffered, and depending upon the system, it might not do quite what you want.
Terminal output doesn't get buffered. Am I missing something?
@user2493235 I was using $| set to Null to read from a socket, where protocol packets were null-separated. Afterwards, trying to read from <STDIN> like above would keep reading until I either entered the null character (Ctrl+shift+@) or EOF (ctrl+D) - pressing enter had no effect. Setting #| to "\n" solved the problem.
5
#! usr/bin/perl
print "How old are you?";
$age = <>;
print "WOW! You are $age years old!";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.