0

I have a perl script that I need to tweak.

The script runs and asks me the manually put in an IP address but I want to hard code in the IP address when it asks me to input it so I need to tell the script to type in the IP and then hit enter to proceed with the script.

Can somebody please tell me how to do this? I'm sure this is probably something extremely basic, but I am not much of a scripter so I'm not sure how to do this.

The script where I need to input the IP and hit enter reads as follows:

print "\nPlease enter the IP address of the node:";
chomp($nodeIP= <STDIN>);

Thanks in advance.

1
  • 1
    It sounds like you are trying to edit the same script that is asking for the IP? Why ask at all? just set $nodeIP to whatever you want. (you could print out the IP too, if you needed to for some reason, but don't bother trying to enter the ip via your program)
    – cam
    Commented Aug 25, 2010 at 22:27

2 Answers 2

5

Easiest is to replace

print "\nPlease enter the IP address of the node:";
chomp($nodeIP= <STDIN>);

with just

$nodeIp="192.168.2.1";

Well using you address of course, not that of my router.

Starting to write to your own stdin, or emulating keystrokes is hairy.

You do not need the chomp() method as that only serves to remove the Enter from the end of the line.

0

Are you trying automate one script with another? If that's the case you might be better off using a tool called expect (Expect: A Tool for Automating Interactions. I've used it for some odd install scripts.

If what you are trying to do is modify a Perl script to just wait for a user prompt then I'd replace:

print "\nPlease enter the IP address of the node:";
chomp($nodeIP= <STDIN>);

With

$nodeIP = "1.2.3.4";
print "\nThe IP is $nodeIP.  If this is correct press ENTER to continue.\n";
<STDIN>

If waiting for an ENTER key press just read STDIN and throw it away.

1
  • Sorry, I know my question looked like it was posed by a 5th grader. I'm not a perl scripter at all. However, your answer gave me enough to figure out what I needed to do which was to just use $nodeIP="xxx";. Thanks for your help. Commented Aug 26, 2010 at 12:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.